Bottom View of a Binary Tree

Asked atMicrosoft
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+
  1. 01Assign root horizontal distance zero.
  2. 02Traverse with a queue carrying node and distance.
  3. 03Move left to distance minus one and right to distance plus one.
  4. 04Overwrite the value stored for each distance as deeper or later nodes arrive.
  5. 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

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question