Given a binary tree, imagine yourself standing on the left side of it,
return the values of the nodes you can see ordered from bottom to top,
then switch to right side of the tree, and return the values of the nodes you can see ordered from top to bottom.
Binary Tree:
1
/ \
2 3
/ \ / \
6 5 5 4
Answer: [6, 2, 1, 3, 4]
Binary Tree:
1
/ \
2 3
\
5
Answer: [5, 2, 1, 3, 5]
Standing on the left side gives the leftmost node of each level, but the ordering must be reversed from bottom to top. Standing on the right side gives the rightmost node level by level from top to bottom. The problem is solved with BFS level traversal and extracting the appropriate visible node at each level.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Meta, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.