← All questions
Coding
Top and Bottom view
Asked at
Paytm
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+
- 01Traverse level by level while carrying horizontal distance.
- 02Store the first value for top view and overwrite for bottom view.
- 03Track minimum and maximum distance or sort map keys.
- 04Emit values from leftmost distance to rightmost.
Reference answer
Then expect these follow-ups
How would vertical order differ?
Tests: tree ordering
Why does BFS make first-seen correct for top view?
Tests: invariants
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