← 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
Hiring now
Nutanix has 108 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.
DevOps Engineer - AI Gateway
Vancouver, British Columbia
Senior Engineering Manager
Vancouver, British Columbia
Advisory Enterprise Account Manager
Remote
Next question