Tree Node Stones – Make Adjacent Difference Exactly 1

Asked atZomato
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. 01Clarify allowed stone values and whether changes have a cost.
  2. 02Root the tree and define DP by node and assigned value.
  3. 03Combine children using only values differing by exactly one.
  4. 04Return the minimum or count requested by the stated objective.

Reference answer

Then expect these follow-ups

  • How would you reconstruct the chosen labels?

    Tests: DP parents

  • Why are only v-1 and v+1 valid child states?

    Tests: constraints

Hiring now

Zomato is hiring 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.
  • Software Engineer – Back End

    Gurugram, HR, India

Or practice this question first

Next question