← Questions

Boundary of a binary tree

0
SnowflakeCodingLast asked Jul 2026

Walk around the outside of a binary tree starting at the root: down the left edge, along the leaves from left to right, then up the right edge. The nodes you pass form the boundary. Return the boundary (or the sum of its values), counting every node once.

Be careful with the root, a tree with no left or right subtree, and nodes that are both an edge node and a leaf. A variant asks the same of a complete, balanced tree.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding