← All questions
Coding
Bottom View of a Binary Tree
Asked at
Microsoft
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Assign root horizontal distance zero.
- 02Traverse with a queue carrying node and distance.
- 03Move left to distance minus one and right to distance plus one.
- 04Overwrite the value stored for each distance as deeper or later nodes arrive.
- 05Output distances in sorted order.
Reference answer
Then expect these follow-ups
How does top view differ from bottom view?
Tests: follow-up reasoning
Why does BFS make depth handling simpler?
Tests: correctness reasoning
Hiring now
Get the Microsoft interview, not just the prep
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Next question