← Uber Interview Insights

Uber·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Uber SWE coding round, got a range-query problem that looked straightforward but has a subtle edge case that'll trip you up if you're not thinking about it carefully. Nothing behavioral, just the one algorithmic problem.

Questions Asked (1)

Q1

You're given an integer array and a list of range queries, each specifying a range and a max decrement value. For each query you can subtract any amount up to that value from each index in the range. Can you always reduce the entire array to zeros by applying all the queries?

Algorithms & Data Structures
Author's notes

My first instinct was to just simulate it, sum up the total capacity per index and compare to nums[i].

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a system of constraints: for each index, the sum of decrements from all queries covering it must equal the original value, and each query's decrement must be between 0 and its max. Use a difference array or sweep line to efficiently compute coverage and check feasibility, or reduce to a flow problem if queries can be partially applied.

Pro tip: Clarify whether queries must be applied fully or can be partially used; this changes the problem from a simple coverage check to a flow/matching problem. Also, mention that if the total maximum decrement per index is less than the array value, it's immediately impossible.

1. Clarify the problem constraints

Ask whether each query must be applied exactly once with a fixed decrement, or if we can choose any amount up to the max per query. Also confirm if queries are independent and can be applied in any order.

2. Formulate as a feasibility problem

For each index, the sum of decrements from all queries covering it must equal the array value. Each query contributes a variable between 0 and its max. This is a system of linear equations with bounds.

3. Check necessary conditions

Compute for each index the total maximum possible decrement (sum of max values of covering queries). If any index's array value exceeds this, return false. Also check that total sum of array equals total sum of applied decrements.

4. Use efficient algorithms to verify sufficiency

If queries can be partially applied, model as a flow network: source to queries (capacity = max), queries to indices (infinite capacity if covers), indices to sink (capacity = array value). Check if max flow equals total array sum. Alternatively, use a greedy sweep with a priority queue if queries are intervals.

5. Discuss complexity and edge cases

Analyze time/space complexity of your approach. Mention edge cases: empty array, queries with max=0, overlapping queries, and indices not covered by any query.

Key Points to Mention

  • Difference array or sweep line for efficient range coverage computation
  • Reduction to max flow / bipartite matching when partial decrements are allowed
  • Necessary condition: total max decrement per index >= array value
  • Greedy approach with priority queue for interval queries
  • Handling of overlapping queries and cumulative decrements
  • Time complexity: O((n+q) log n) for sweep, O(V^2 E) for flow

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