FastPrepRight Edge of a Binary Search Tree Built From a List
Problems/Right Edge of a Binary Search Tree Built From a List

Right Edge of a Binary Search Tree Built From a List

Capital One logoCapital One● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A September 2015 Capital One software engineer report, from a Richmond visit that followed a campus interview, lists four programming problems to solve in 45 minutes. One of them is building a binary search tree and returning its rightmost node.

The report does not say how the tree is given. Here the values arrive as a list to insert in order into an empty tree, and equal values never occur. The answer lists the values on the tree's right edge: the root, its right child, that child's right child and so on down to the rightmost node. There are up to 1000 distinct values. These are our choices.

Our version is about 70% the same as the reported question.

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 values are 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
See Capital One hiring insights
Saved
class Solution {
    public int[] rightEdge(int[] values) {
        // Write your code here.
    }
}
Checking account…