Binary Tree Right View
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reported this one in September 2026, and the detail that matters is in the examples: root = [1,2,3,null,5,null,4] returns [1,3,4]. The 4 shows up even though it sits under the left subtree's sibling path, so "just follow right children" is wrong. It's a Binary Tree Right View, a tree traversal problem that's easy once you see it and ugly if you blank. If your Amazon OA lands in the next couple of days, learn the level-by-level idea below. StealthCoder is the safety net running invisibly during the live assessment if your mind goes empty.
The problem
Given the root of a binary tree, imagine viewing the tree from its right side. Return the value of the visible node at each depth, ordered from the root level downward. For an empty tree, return an empty array. Function rightSideView(root: TreeNode) → int[] Examples Example 1 root = [1,2,3,null,5,null,4] return = [1,3,4] The rightmost visible values at successive levels are 1, 3, and 4. Example 2 root = [1,null,3] return = [1,3] The right child is visible below the root. Example 3 root = [] return = [] An empty tree has no visible levels. Constraints The tree contains between 0 and 10000 nodes. -10^9 <= Node.val <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to track depth. Do a BFS with a queue, and at each level record the last node you process. That's the rightmost visible value. Alternative: DFS that visits right child first, and adds a value only when the current depth equals the result size. Both run O(n) time. The common pitfall is walking only right pointers, which fails on Example 1 where 4 is reached through the left branch's descendants at that level. Another miss is the empty tree. Return an empty array before touching the queue. With up to 10000 nodes, recursion depth on a skewed tree can get deep, so BFS is the safer pick. Values go up to 10^9 in magnitude, but you never do arithmetic on them, so overflow isn't a concern. If you freeze on the live OA, StealthCoder is the hedge that reads the problem and hands you the level-order solution.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Binary Tree Right View cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as binary tree right side view. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Binary Tree Right View FAQ
What's the trick to Binary Tree Right View?+
Think by depth, not by pointer. At each level, the visible node is the last one in left-to-right order. BFS with a queue and keep the final node of each level, or DFS right-first and record the first node you see at each new depth.
Why doesn't following right children work?+
Example 1 shows it. Node 4 is visible at depth 2 but the right child of 3 is null in that branch path logic only if you stop early. A level can be exposed by a left subtree when the right side is shorter, so you must consider every node at each depth.
BFS or DFS for this Amazon OA question?+
BFS is the safer default. It maps directly to the level idea and avoids deep recursion on a skewed tree with 10000 nodes. DFS right-first is shorter to write, so pick whichever you can code cleanly without bugs under pressure.
What edge cases should I test?+
Empty tree returns an empty array. A single node returns just its value. A tree with only a left chain should return every node. A right-heavy tree with a shorter left side is also worth checking, plus negative values, which don't change the logic.
How do I prepare in 48 hours?+
Write the BFS version from scratch twice, then the right-first DFS once. Trace Example 1 by hand with your level boundaries. Then do a couple of other level-order variations so the queue-per-level loop feels automatic. That's enough for this one.