Right Edge of a Binary Search Tree Built From a List
Updated
Problem statement
Start with an empty binary search tree: a value smaller than a node goes into that node's left part, a larger value into its right part. Insert the numbers of values one by one in the order given. All numbers are different.
Then begin at the root and keep stepping to the right child until there is none. Return the values of all the nodes you stood on, from the root down to the rightmost node.
Function
rightEdge(values: int[]) → int[]Examples
Example 1
values = [40,15,55,8,70,62]return = [40,55,70]Insert 40 as the root. 15 goes left. 55 and 70 go right, one below the other. 8 goes left of 15, and 62 goes left of 70. From the root, always going right visits 40, 55, 70.
Example 2
values = [30,20,10,5]return = [30]Every value is smaller than the one before, so each goes to the left. The root 30 has no right child, so the edge is just [30].
Example 3
values = [6]return = [6]One value makes a one-node tree whose edge is that node.
Constraints
1 <= values.length <= 1000-10^9 <= values[i] <= 10^9- All numbers in
valuesare different.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Insert into a Left-Complete Binary TreeRubrik · ONSITE INTERVIEW
- Kth Closest Element in a BSTLinkedIn · ONSITE INTERVIEW
- Shortest Path Between BST NodesGoogle · ONSITE INTERVIEW
- Repeated BST Range Sum and AverageMeta · ONSITE INTERVIEW
- Lowest Common Ancestor in a BSTPeopleStrong · ONSITE INTERVIEW
- Delete Node in a BSTBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Validate Binary Search TreeTokopedia · ONSITE INTERVIEW
- Build a Perfect Binary Search TreeExpedia · ONSITE INTERVIEW
- Next Larger Value in a BSTMicrosoft · ONSITE INTERVIEW
- Lowest Common Ancestor in an Inserted BSTAmazon · PHONE SCREEN
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences