Back to problems

Return all root-to-leaf path sums

Algorithm · Meta · Medium

Given the root of a binary tree, where every node stores an integer value that may be negative, compute the sum of values along each path that starts at the root and ends at a leaf. A leaf is defined as a node with no children. Return the root-to-leaf sums in depth-first search order, always visiting the left child before the right child. If the tree is empty, return an empty list. For the examples, a node is represented as [value, left, right], and null indicates a missing…

Checking your access…