The problem reads clean on paper but I kept second-guessing the edge cases.
Break the problem into three distinct traversals: left boundary (excluding leaves), leaves (left-to-right), and right boundary (excluding leaves, collected bottom-up). Use DFS to collect each part, then concatenate while ensuring no duplicates, especially avoiding the root and leaf nodes in boundary traversals.
Pro tip: Clarify edge cases upfront, such as a single-node tree or skewed trees, and mention that the root should only be added once. This shows attention to detail and prevents off-by-one errors.
Check if the root is null; if so, return an empty list. Otherwise, add the root value to the result list (since it's always part of the boundary).
Traverse from the root's left child down the left side, adding nodes that are not leaves. Prefer left child over right child when both exist.
Perform a DFS (pre-order) to find all leaf nodes (nodes with no children) and add their values to the result in left-to-right order.
Traverse from the root's right child down the right side, adding nodes that are not leaves. Prefer right child over left child, and collect values in a temporary list to reverse before adding to the result.
Concatenate the root, left boundary, leaves, and reversed right boundary. Ensure no duplicates by excluding leaves from boundary traversals and handling the root separately.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.