← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE technical phone screen, one coding question the whole time. Pretty focused on BST traversal with a twist, and they wanted iterative only so no recursion cop-outs.

Questions Asked (1)

Q1

Given the root of a binary search tree and an integer k, return the k-th largest element (1-indexed). You must write an iterative solution, not recursive.

Algorithms & Data Structures
Author's notes

It's basically a reversed in-order traversal.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use an iterative in-order traversal (left, root, right) to visit nodes in ascending order, but stop after visiting (n - k + 1) nodes to find the k-th largest. Alternatively, perform a reverse in-order traversal (right, root, left) and stop at the k-th visited node. Both approaches use an explicit stack to avoid recursion.

Pro tip: Clarify whether k is 1-indexed and whether the tree can be modified; then mention that reverse in-order is more efficient because it stops early without needing to know the total number of nodes. Also, discuss edge cases like k > number of nodes or k <= 0.

1. Understand the problem and constraints

Confirm that k is 1-indexed, the tree is a BST, and the solution must be iterative. Discuss edge cases such as k being larger than the number of nodes or k <= 0.

2. Choose traversal strategy

Decide between in-order (ascending) or reverse in-order (descending). Reverse in-order is preferred because it directly finds the k-th largest without needing the total node count.

3. Implement iterative traversal with a stack

Use a stack to simulate recursion. For reverse in-order, push all right children, then process the node, then move to the left child. Keep a counter to track visited nodes.

4. Stop early and return the result

Once the counter reaches k, return the current node's value. If traversal completes without reaching k, handle the invalid case (e.g., return -1 or throw an exception).

5. Analyze complexity and test

State time complexity O(h + k) where h is tree height, and space complexity O(h). Walk through a small example to verify correctness.

Key Points to Mention

  • BST property: in-order traversal yields sorted ascending order; reverse in-order yields descending order.
  • Iterative implementation using an explicit stack to avoid recursion.
  • Early termination: stop after visiting k nodes in reverse in-order.
  • Time complexity: O(h + k) for reverse in-order, where h is the height of the tree.
  • Space complexity: O(h) due to stack usage.
  • Edge cases: k <= 0, k > number of nodes, empty tree.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.