Right-Side View of a Driver Referral Tree
Last updated: November 29, 2026
Quick Overview
Driver referrals form a binary tree where each driver refers at most two others. Return the driver IDs you would see looking at the tree from the right side, one per level from top to bottom.
Uber
November 29, 20260
0
0 solved
Driver referrals form a binary tree where each driver refers at most two others. Return the driver IDs you would see looking at the tree from the right side, one per level from top to bottom.
A short online assessment item for Uber new-grad and early-career loops. It checks level-order traversal and whether you can pick out the last node per level without extra passes.
What the Interviewer Expects
- Uses BFS level by level and records the last node of each level
- Alternatively uses DFS visiting right child first and recording the first node per depth
- Handles an empty tree
- States O(n) time and O(w) or O(h) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the left-side view instead with minimal changes.
- How would you return the full level-order list grouped by level?
- Can you do this with O(h) extra space instead of O(w)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: root of a binary tree of driver IDs (may be empty).
- Output: list of IDs, the rightmost node at each depth, top to bottom.
- A left-subtree node is visible if the right subtree is shorter at...
High-Level Design
Process the tree level by level with a queue. For each level we know its size up front, so the last node dequeued at that level is the one visible from the right. An equivalent DFS approach visits rig...