Binary Tree Right View
Reported by candidates from Pinecone's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Pinecone reported this one in October 2026, and the statement hands you the whole trick: return the visible node at each depth, from the root downward. That's Binary Tree Right View, a tree problem with a level-by-level answer. If you've got an OA invite and 48 hours, this is a good one to see coming. The empty tree case returns an empty array, and the tree can hold up to 10000 nodes. It's short, clean, and easy to overthink. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea fits in one breath.
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. Return an empty array for an empty tree. Function rightSideView(root: TreeNode) → int[] Examples Example 1 root = [1,2,3,null,5,null,4] return = [1,3,4] The rightmost values at successive depths 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: the visible node at each depth is the last node on that level. Run a BFS with a queue, process one level at a time by snapshotting the queue size, and keep the final node's value from each level. Or use DFS, visit right child before left, and record a value the first time you reach a new depth. Both run in O(n) time. The common pitfall is assuming the answer is just the chain of right children. Example 1 shows why that's wrong: a node on the left side can be the rightmost one at its depth when the right side stops early. Another miss is forgetting the empty root, which must return []. With up to 10000 nodes, a skewed tree makes recursive DFS deep, so BFS is the safer pick. If you freeze live, StealthCoder is the hedge that reads the problem and hands you the level-order template.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
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 would have shipped this the night before his JPMorgan OA if he'd had it.
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 Pinecone's OA.
Pinecone reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Binary Tree Right View FAQ
What's the trick to Binary Tree Right View?+
The visible node at each depth is the last one on that level. Do a level-order BFS and take the final node of each level. Or do DFS visiting right first, and record the first node you see at each new depth. Either way it's O(n).
How hard is this really for the Pinecone OA?+
It's a standard medium-easy tree problem. If you know level-order traversal, you've basically solved it. The only real difficulty is not mistaking it for 'follow right children only,' which Example 1 breaks immediately.
BFS or DFS, which should I use?+
BFS is the safer default. Snapshot the queue size per level and keep the last value. DFS with right-first ordering works too, but with 10000 nodes a skewed tree can get deep, so recursion limits are worth thinking about.
What edge cases should I test?+
Test the empty tree, which returns []. Test a single node. Test a tree where the right subtree is shorter than the left, so a left-side node shows up in the result. Also check a skewed tree with only left children.
How do I prepare in 48 hours?+
Write level-order traversal from memory until it's automatic, then write the right-first DFS version. Trace Example 1 by hand on paper. Practice a couple of related tree traversals too, so the queue-per-level pattern feels routine.