Skip to content
C

Boundary Traversal

Hardjavapythonccppjavascript

Print the boundary of a binary tree in anti-clockwise order, without repeating any node: the root, then the left boundary top-down (excluding leaves), then all leaves left-to-right, then the right boundary bottom-up (excluding leaves).

Input Format

The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null).

Output Format

Print the boundary node values separated by single spaces.

Input (stdin)

Output

Run your code to see output here...