Boundary traversal of binary tree
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`.
Implement
boundary_traversal(arr: list[int]) → list[int]Examples
in
[[1,2,3,4,5,6,7]]out[1,2,4,5,6,7,3]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[1,2,3,4,5,6,7]][1,2,4,5,6,7,3]not run yetsample