← All questions
MediumCoding
Sum Root to Leaf Numbers
Asked at
BitGo
Meta
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+
- 01Carry the numeric prefix from root to current node.
- 02Extend it as current times ten plus node value.
- 03At a leaf, return the complete number.
- 04Sum left and right recursive results, handling null as zero.
Reference answer
Then expect these follow-ups
How would you collect the actual path strings?
Tests: path state
What changes for base b digits?
Tests: generalization
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