← Uber Interview Insights

Uber·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE online assessment, one algorithmic problem centered on prefix sums and binary search. Pretty clean problem once you see the pattern, but the off-by-one stuff in the binary search bounds is where people apparently blow it.

Questions Asked (1)

Q1

Given a non-decreasing array of stall prices and a list of queries, each with a starting position and a budget, find the maximum number of items you can buy greedily moving rightward from that position without exceeding the budget.

Algorithms & Data Structures
Author's notes

The greedy insight is pretty quick to get to since prices only go up, so you always want to buy left to right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that 'greedily moving rightward' means buying items in order from the starting position until the budget is exhausted. Then, explain that since the array is non-decreasing, the sum of any contiguous subarray can be computed efficiently, and for each query, you can use binary search on prefix sums to find the farthest index reachable within the budget. Finally, discuss time complexity and possible optimizations for multiple queries.

Pro tip: Mention that if there are many queries, you can precompute prefix sums and use binary search per query, achieving O(log n) per query after O(n) preprocessing. Also, note that if queries are offline, you might sort them and use two pointers to achieve O(n + q) total time.

1. Clarify the problem

Confirm that 'greedily moving rightward' means buying items sequentially from the starting index until the next item would exceed the remaining budget. Ensure you understand that the array is non-decreasing, which guarantees that prices increase or stay the same as you move right.

2. Preprocess for efficient range sums

Compute a prefix sum array where prefix[i] is the sum of prices from index 0 to i-1. This allows O(1) calculation of the sum of any contiguous subarray.

3. Answer each query with binary search

For a query (start, budget), the total cost to buy items from start to index j is prefix[j+1] - prefix[start]. Use binary search to find the largest j such that this sum is ≤ budget. The number of items bought is j - start + 1.

4. Analyze complexity and edge cases

State that preprocessing takes O(n) time and each query takes O(log n) time. Handle edge cases: budget insufficient for even the first item (answer 0), start index out of bounds, and large budgets that allow buying all remaining items.

5. Discuss optimizations for multiple queries

If there are many queries, consider offline processing: sort queries by start index and use a sliding window or two pointers to achieve O(n + q) total time. Alternatively, if queries are online, the binary search approach is optimal.

Key Points to Mention

  • Prefix sums for O(1) range sum queries
  • Binary search on the prefix sum array to find the maximum index within budget
  • Time complexity: O(n) preprocessing, O(log n) per query
  • Handling edge cases: insufficient budget, start index at end, budget covering all items
  • Possible optimization for multiple queries: offline sorting and two pointers
  • The non-decreasing property ensures that once an item is too expensive, all subsequent items are also too expensive, so greedy buying is optimal

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