Use BFS level-order traversal, recording the last node's value at each level. Alternatively, use DFS prioritizing the right child and track the maximum depth seen so far to capture the rightmost node at each depth.
Pro tip: Clarify with the interviewer whether the tree can be empty or have only one node, and discuss the trade-offs between BFS and DFS in terms of space complexity and code simplicity.
Confirm that 'visible from the right side' means the rightmost node at each depth level, and that the output should be ordered from top to bottom.
Decide between BFS (level-order traversal) and DFS (right-first traversal with depth tracking). BFS is often more intuitive for level-based problems.
Use a queue to process nodes level by level. For each level, record the value of the last node processed (the rightmost node).
Traverse right subtree first, then left. Keep track of the current depth and a list of results. If the current depth equals the list size, append the node's value.
State that both approaches run in O(n) time and O(n) space in the worst case (BFS queue or DFS recursion stack).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.