Uber Phone Screen

Anonymous User
1077
Apr 18, 2024
Apr 18, 2024

Given a binary search tree (BST) find the kth largest element.

Example:

         10
       /       \
    4           20
  /             /    \
2           15        40

k = 2

output: 20

Method signature:
public int kthLargest(TreeNode root, int k) {}

Follow up:
Given a list of kth values find return the number cooresponding

public int kthLargest(TreeNode root, List k) {}

Example:

             10
         /       \
      4          20
	/          /     \
  2           15     40

k = [2, 1, 30, 6]

output: [20, 40, null, 2]

Talked through solution, got buy in from interviewer, and solved problem on time.

Got rejected. Life is funny that way lol

Comments (4)