← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Did a technical phone screen for a software engineer role at Uber. One algorithmic problem, range-update style, which I've seen variants of before but still had to think through carefully.

Questions Asked (1)

Q1

You have an integer array and a list of queries, each specifying a range and a value. Each query lets you decrease elements in that range by any non-negative amount up to the given value. Can you make every element zero after processing all queries?

Algorithms & Data Structures
Author's notes

The key insight is that the order of queries doesn't actually matter for whether it's possible.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a difference array where each query adds a constraint on the maximum cumulative decrement at each position. Use a sweep line to check if the required decrements can be satisfied without exceeding the query limits, ensuring that the total decrement at each index equals the original value.

Pro tip: Clarify that queries can be applied in any order and that each query's decrement is independent; this allows a greedy or difference-array approach. Mention that if the array has negative values or queries with negative values, the problem becomes infeasible, so handle edge cases explicitly.

1. Understand the problem and constraints

Restate the problem: given an array and range-decrement queries with a max decrement per query, determine if we can reduce all elements to zero. Clarify that each query can decrement each element in its range by any amount up to the given value, independently.

2. Model as a difference array

For each query (L, R, V), it imposes that the total decrement at any index i in [L, R] cannot exceed V from this query alone. Use a difference array to track the maximum allowed decrement at each position from all queries.

3. Sweep to compute cumulative limits

Perform a left-to-right sweep, maintaining the current maximum allowed decrement from active queries. At each index, check if the array value is less than or equal to this limit; if not, return false.

4. Verify feasibility with greedy assignment

Compute the total possible decrement at each index by summing V over all queries covering that index using a difference array. Then check if array[i] ≤ total possible decrement for all i. If any array[i] is negative or any V is negative, return false.

5. Discuss complexity and edge cases

Time complexity O(n + q) with difference array, space O(n). Mention edge cases: empty array, no queries, queries with V=0, negative values, and overlapping queries.

Key Points to Mention

  • Difference array technique for range updates and point queries
  • Necessary and sufficient condition: array[i] ≤ sum of V for queries covering i
  • Handling negative values in array or queries (immediate false)
  • Time and space complexity analysis (O(n+q) time, O(n) space)
  • Independence of decrement choices per element per query
  • Edge cases: empty array, no queries, zero values, overlapping ranges

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