← All questions
Coding
Return Maximum number of turns in a tree from root to lead node
Asked at
Nutanix
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+
- 01Clarify whether leaf node and left-right turns are intended
- 02Traverse from root carrying previous direction and count
- 03Increment only when current edge changes direction
- 04Update a global or returned maximum at leaves
- 05Test single paths and alternating directions
Reference answer
Then expect these follow-ups
How would you return the leaf path that achieves the maximum?
Tests: path reconstruction
How would you write this iteratively with an explicit stack?
Tests: tree traversal
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