← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber SWE interview with a sliding window problem that looks straightforward but has a few gotchas once you start counting pairs correctly.

Questions Asked (1)

Q1

Given an integer array and a value k, count how many contiguous subarrays contain at least k pairs of equal elements, where each distinct value contributes at most one pair no matter how many times it appears.

Algorithms & Data Structures
Author's notes

My first instinct was two pointers and I think that's right, but I fumbled the pair-counting logic initially.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and constraints, then propose an efficient solution using a sliding window with a frequency map to track distinct values and count pairs. Explain how to maintain the number of pairs as the window expands and shrinks, and how to count valid subarrays in O(n) time.

Pro tip: Emphasize that each distinct value contributes at most one pair, so the pair count is simply the number of distinct values with frequency ≥ 2. This simplifies the sliding window logic and avoids overcounting.

1. Clarify the problem and constraints

Confirm the definition of a pair (two equal elements) and that each distinct value contributes at most one pair. Ask about input size, value range, and expected time complexity.

2. Design the sliding window approach

Use two pointers (left and right) to represent a window. Maintain a frequency map of elements in the window and a variable `pairs` counting distinct values with frequency ≥ 2.

3. Expand and shrink the window

Expand right, update frequency and pairs. While pairs ≥ k, add (n - right) to the answer and shrink left, updating frequency and pairs accordingly.

4. Handle edge cases and complexity

Discuss edge cases like k=0, empty array, or no valid subarrays. State that the algorithm runs in O(n) time and O(n) space for the frequency map.

5. Test with examples

Walk through a small example to verify correctness, such as array [1,2,1,2,1] and k=2, showing how the window and pairs change.

Key Points to Mention

  • Sliding window technique for contiguous subarrays
  • Frequency map to track counts of distinct values
  • Pair count as number of distinct values with frequency ≥ 2
  • Time complexity O(n) and space complexity O(n)
  • Counting valid subarrays by adding (n - right) when condition met
  • Edge cases: k=0, k larger than possible pairs, empty array

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