Easy · Trees
Print all root to leaf paths
Given the root of a binary tree, return every root-to-leaf path as a list of node values, with the paths ordered by their leaves from left to right (a leaf is a node with no children; an empty tree has no paths).
Examples
Example 1
{
"tree": [1, 2, 3, 4, 5, null, 6]
}Output: 3 paths
Example 2
{
"tree": [1, 2, 3]
}Output: 2 paths
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.