← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Uber phone screen for a SWE role, basically one algorithmic problem the whole time. Classic sliding window stuff but the dual-deque angle tripped me up a bit.

Questions Asked (1)

Q1

Given an integer array and a limit value, find the length of the longest contiguous subarray where the absolute difference between any two elements is at most the given limit.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew sliding window was the right direction but fumbled on how to track min and max efficiently inside the window.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window with two monotonic deques to maintain the min and max in the current window, expanding the right pointer and shrinking the left when the difference exceeds the limit. This yields O(n) time and O(n) space, which is optimal for this problem.

Pro tip: Mention that the monotonic deque approach is preferred over a heap-based solution because it achieves O(n) time and avoids O(log n) operations, and clarify that the absolute difference condition is equivalent to max - min <= limit.

1. Clarify the problem and constraints

Confirm that the subarray must be contiguous, the limit is inclusive, and discuss edge cases like empty array or limit < 0. Ask about input size to determine if O(n) is necessary.

2. Outline a brute-force approach

Briefly describe checking all subarrays in O(n^2) time to establish a baseline, then explain why it's inefficient for large inputs.

3. Introduce the sliding window with monotonic deques

Explain that you'll maintain two deques: one for minimum and one for maximum in the current window. Expand the right pointer, update deques, and shrink from the left while max - min > limit.

4. Walk through an example and analyze complexity

Trace the algorithm on a small array to demonstrate correctness. State that each element is added and removed at most once, giving O(n) time and O(n) space.

5. Discuss trade-offs and alternatives

Compare with a heap-based approach (O(n log n)) or a balanced BST, and mention that the deque method is optimal for this problem. Also note that if the array is sorted, a simpler two-pointer approach works.

Key Points to Mention

  • Sliding window technique to maintain a contiguous subarray.
  • Monotonic deques to efficiently track min and max in O(1) amortized time.
  • Time complexity O(n) and space complexity O(n).
  • The condition max - min <= limit is equivalent to the absolute difference condition.
  • Handling edge cases: empty array, limit < 0, all elements equal.
  • Trade-offs: deque vs heap vs balanced BST, and when each is appropriate.

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