Top and Bottom view

Asked atPaytm
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. 01Traverse level by level while carrying horizontal distance.
  2. 02Store the first value for top view and overwrite for bottom view.
  3. 03Track minimum and maximum distance or sort map keys.
  4. 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

Hiring now

Paytm has 128 open roles right now

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.
  • Senior Software Engineer – Backend (Travel)

    Bangalore, Karnataka

  • Junior Marketing Manager

    Luxembourg

  • Collection Manager- North- Business- Lending Collections

    Aligarh, Uttar Pradesh

Or practice this question first

Next question