Рет қаралды 82,186
Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe.com/pricing
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions
Question: You are given 3 things. The root of a binary tree, a single start node in the binary tree, and a number k. Return all nodes that are k "hops" away from the start node in the binary tree. Return a list of the values held at those nodes.
Complexities
n = total amount of nodes in the binary tree
m = total edges
Time: O( n + m )
This is standard to Breadth First Search. We upper bound the time by the number of nodes we can visit and edges we can traverse (at maximum).
Space: O( n )
We have a hashtable upper bounded by n mappings, a mapping to each node's parent.
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: kzfaq.info/love/Of7UPMHBjAavgD0Qw5q5ww
Tuschar Roy: kzfaq.info
GeeksForGeeks: kzfaq.info/love/0RhatS1pyxInC00YKjjBqQ
Jarvis Johnson: kzfaq.info
Success In Tech: kzfaq.info/love/-vYrOAmtrx9sBzJAf3x_xw