← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Uber SWE interview with a sliding window problem that looks straightforward until you actually have to implement it under pressure.

Questions Asked (1)

Q1

Given an array of integers and a limit value, find the length of the longest subarray where the absolute difference between any two elements stays within that limit.

Algorithms & Data Structures
Author's notes

The sliding window part clicked pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window (two pointers) to maintain a subarray where the difference between the maximum and minimum elements is at most the limit. Efficiently track the max and min within the window using monotonic deques, expanding the right pointer and shrinking the left when the condition is violated. Keep track of the maximum window length seen.

Pro tip: Mention that the monotonic deque approach gives O(n) time, which is optimal, and briefly compare it to the O(n log n) multiset approach to show awareness of trade-offs. Also, clarify that the condition 'absolute difference between any two elements' is equivalent to max - min <= limit.

1. Clarify the problem and constraints

Confirm that the subarray must be contiguous and that the condition applies to all pairs, which simplifies to max - min <= limit. Ask about input size to determine if O(n) is necessary.

2. Choose the right data structures

Use two monotonic deques: one for maintaining the maximum (decreasing order) and one for the minimum (increasing order) in the current window. This allows O(1) amortized access to the max and min.

3. Implement the sliding window

Initialize left = 0, maxLen = 0. Iterate right from 0 to n-1, updating the deques. While max - min > limit, increment left and remove elements from deques if they fall out of the window. Update maxLen with the current window size.

4. Analyze complexity and edge cases

Explain that each element is added and removed from each deque at most once, giving O(n) time and O(n) space. Discuss edge cases like empty array, limit = 0, or all elements equal.

5. Test with examples and conclude

Walk through a small example to verify correctness, then summarize the approach and its efficiency. Mention alternative approaches (e.g., multiset) and why the deque method is preferred.

Key Points to Mention

  • Sliding window technique with two pointers
  • Monotonic deques for O(1) max/min retrieval
  • Time complexity O(n) and space complexity O(n)
  • Equivalence of 'absolute difference between any two elements' to max - min <= limit
  • Handling edge cases (empty array, limit = 0, negative numbers)
  • Comparison with alternative O(n log n) approaches using balanced BST or multiset

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