Binary Tree Right Side View
Return the rightmost visible node value at each depth of a binary tree, starting at the root.
Example 1
root = [1,2,3,null,5,null,4][1,3,4]Explanation
The rightmost nodes at depths 0,1,2 are 1,3,4.
Example 2
root = [1,2,null,3][1,2,3]Explanation
Without a right branch the left chain is still visible: 1,2,3.
Example 3
root = [][]Explanation
An empty tree contributes no visible nodes.
Constraints
- 0 <= number of nodes <= 1000
- Trees are breadth-first arrays with null holes
Function contract
rightSideViewArguments: treeSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,2,3,null,5,null,4]