Code Room
CodingHardcod-g064
Subject Tree traversalLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.