Compute left and right views once
MetaSoftware Engineer · Technical ScreenLast updated
This question evaluates understanding of binary tree traversal, depth tracking, and view computation for left and right perspectives, plus the ability to implement a concurrent single-pass traversal while handling edge cases such as empty trees and duplicate keys.
Given the root of a binary search tree, output two lists: the nodes visible from the left side and the nodes visible from the right side, from top to bottom. Implement a single-pass traversal that computes both views concurrently. Discuss iterative vs. recursive strategies, how you track depth and first/last-at-depth nodes, and analyze time/space complexity. Handle empty trees and trees with duplicate keys.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.