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

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