Sum Root to Leaf Numbers

Medium · Trees · about 15 minutes

Asked at Meta, Oracle, Bloomberg, Google, Amazon, Morgan Stanley, Dell Technologies, Nutanix.

Every node of a binary tree holds a digit 0–9. Each root-to-leaf path spells a number (for example the path 1 → 2 → 3 is 123). Return the sum of all those numbers.

Related guides