Print Tree Perimeter
Given a binary tree, print its perimeter nodes.
Statement
Given the root node of a binary tree, print the nodes that form its perimeter (boundary). We must print the perimeter of the binary tree in three phases (order is important):
- Left boundary
- Leaf nodes
- Right boundary
Example
In the following tree, the nodes highlighted in green, form the perimeter.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.