Binary Tree Right View
Updated
Problem statement
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) → List<Integer>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
0and10000nodes. -10^9 <= Node.val <= 10^9.
More Pinecone Online Assessment questions
Similar questions at other companies
- Base Unit ConversionsAdobe · OAAdobe interview questions
- Minimum-Sum Tree Fill with Unit StepsVisa · OAVisa interview questions
- Minimum N-ary Tree Depth DeletionsSnowflake · OA · PHONE SCREENSnowflake interview questions
- Tree Pythagorean TriplesIBM · OAIBM interview questions
- Count LevelsBlackRock · OABlackRock interview questions
- Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
- Longest Transfer Time in a Server TreeRippling · OARippling interview questions
- TikTok: Secondary InfluencersTikTok · OATikTok interview questions
- Find Min Distance to Furthest Node (Google Tokyo)Google · OAGoogle interview questions
- Binary Tree Level OrderMorgan Stanley · OAMorgan Stanley interview questions