MENU

Fun & Interesting

All Nodes Distance K In A Binary Tree - Performing Bidirectional Search On A Tree Using A Hashtable

Back To Back SWE 83,754 6 years ago
Video Not Working? Fix It Now

Free 5-Day Mini-Course: https://backtobackswe.com Try Our Full Platform: https://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: https://www.youtube.com/channel/UCOf7UPMHBjAavgD0Qw5q5ww Tuschar Roy: https://www.youtube.com/user/tusharroy2525 GeeksForGeeks: https://www.youtube.com/channel/UC0RhatS1pyxInC00YKjjBqQ Jarvis Johnson: https://www.youtube.com/user/VSympathyV Success In Tech: https://www.youtube.com/channel/UC-vYrOAmtrx9sBzJAf3x_xw

Comment