Binary Tree Right Side View
Updated
Problem statement
Given the root of a binary tree, imagine standing to the right of it. Return the value of the node visible at each depth, ordered from the root level downward.
When several nodes share a depth, the rightmost node is visible.
Function
rightSideView(root: TreeNode) → List<Integer>Examples
Example 1
root = [1,2,3,null,5,null,4]return = [1,3,4]The rightmost values at depths zero, one, and two are 1, 3, and 4.
Example 2
root = [1,null,3]return = [1,3]The tree has one visible node at each of its two depths.
Example 3
root = []return = []An empty tree has no visible nodes.
Constraints
- The tree contains from
0through100000nodes. - Every node value fits in a signed 32-bit integer.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
- Maximum-Scoring Consecutive Tree LevelsJane Street · PHONE SCREENJane Street interview questions
- Minimum Edits to a Perfect Binary TreeSnowflake · PHONE SCREENSnowflake interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Group Identical Tree LevelsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Zigzag Level-Order TraversalFlipkart · ONSITE INTERVIEW
- Same Binary TreeOdoo · PHONE SCREENOdoo interview questions
- Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Binary Tree Nodes at Distance KApple · ONSITE INTERVIEWApple interview questions