Boundary traversal of binary tree
Your task
Given a binary tree as a level-order array arr (null for missing), return its anti-clockwise boundary traversal: the root first, then the left boundary top-down excluding leaves, then all leaves left to right, then the right boundary bottom-up excluding leaves. Each node appears exactly once. The 'left boundary' follows left children when present, otherwise right; the 'right boundary' is the mirror. Return the list of values. 0 <= node count <= 10000.
Examples
boundary_traversal(arr: list[int]) -> list[int]Example 1
Input
boundary_traversal([1, 2, 3, 4, 5, 6, 7])Output
[1, 2, 4, 5, 6, 7, 3]