← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Uber SWE interview with a clean algorithmic problem that I probably overcomplicated before landing on the right approach. Nothing too wild, but the binary search piece tripped me up for a minute.

Questions Asked (1)

Q1

Given an array of numbers and a list of query values, for each query return the maximum length of a subsequence whose elements sum to no more than that query value.

Algorithms & Data Structures
Author's notes

I jumped straight to thinking about dynamic programming and wasted a few minutes going down that road.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient algorithm that preprocesses the array to answer multiple queries quickly. Explain how sorting and prefix sums can be used to find the maximum number of elements that sum to at most each query value.

Pro tip: Mention that sorting the array is optimal because to maximize the count of elements under a sum constraint, you should always pick the smallest elements first. This greedy insight simplifies the problem and leads to an efficient solution.

1. Clarify the problem

Ask about constraints: array size, number of queries, value ranges, and whether elements can be negative. Confirm that subsequence means any subset of elements (order doesn't matter).

2. Identify the greedy strategy

Explain that to maximize the number of elements under a sum limit, we should select the smallest elements first. Sorting the array enables this.

3. Preprocess for efficient queries

Sort the array and compute prefix sums. For each query, use binary search on the prefix sums to find the largest index where the sum is ≤ query value. The count is that index + 1.

4. Analyze complexity

Sorting takes O(n log n), prefix sums O(n), and each query O(log n) via binary search. Total O(n log n + q log n), which is efficient for large inputs.

5. Handle edge cases

Discuss cases where query is smaller than the smallest element (return 0), or larger than total sum (return n). Also consider negative numbers if allowed, which would require a different approach.

Key Points to Mention

  • Sorting the array to enable greedy selection of smallest elements
  • Prefix sums to quickly compute cumulative sums
  • Binary search on prefix sums to answer each query in O(log n)
  • Time complexity: O(n log n + q log n) and space complexity O(n)
  • Edge cases: empty array, query less than smallest element, query greater than total sum
  • If negative numbers are allowed, the greedy approach fails and a different algorithm (e.g., dynamic programming) may be needed

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