I went straight to the recursive solution first because it felt more natural, then had to backtrack and build the iterative BFS version.
Start by clarifying the problem and edge cases, then present both iterative BFS and recursive DFS solutions with clear code and complexity analysis. Emphasize the trade-offs between the two approaches and how they handle skewed trees and missing children.
Pro tip: In interviews, always discuss edge cases like empty tree, single node, and skewed trees before coding, and mention that the recursive solution can be optimized to O(1) space if recursion stack is not counted, but be transparent about the trade-offs.
Restate the problem to ensure understanding: left side view means the first node at each depth. Discuss edge cases: empty tree, single node, skewed left/right, and missing children.
Explain level-order traversal using a queue. At each level, record the first node's value. Handle missing children by only enqueuing non-null nodes.
Use pre-order traversal (root, left, right) and track the current depth. If the depth is visited for the first time, add the node's value to the result. This ensures the leftmost node at each depth is recorded.
For both solutions, time complexity is O(n) where n is number of nodes. Space: BFS O(w) where w is max width; recursive O(h) where h is height (skewed tree O(n)).
Compare BFS vs DFS: BFS uses more memory for wide trees, DFS uses recursion stack. Discuss handling skewed trees and missing children in both implementations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.