← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Uber SWE interview with a straightforward array/string problem. Nothing too wild, just index tracking under a time constraint.

Questions Asked (1)

Q1

Given an array of strings and two distinct words that both appear in it, find the minimum index distance between any occurrence of the two words.

Algorithms & Data Structures
Author's notes

Pretty clean problem once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the words are distinct and both appear, then propose a single-pass solution that tracks the most recent index of each word and updates the minimum distance whenever either word is encountered. This achieves O(n) time and O(1) space, which is optimal since every element may need to be examined.

Pro tip: Mention that if the array is static and many queries will be made, you could preprocess positions of each word and use binary search to answer each query in O(log n) time, but for a single query the linear scan is optimal.

1. Clarify the problem

Confirm that the two words are distinct, both appear in the array, and that distance is measured as the absolute difference of indices. Ask if the array can be modified or if multiple queries are expected.

2. Discuss brute force

Mention that a naive approach would compare every occurrence of word1 with every occurrence of word2, which is O(n^2) in the worst case. This shows you understand the baseline but also its inefficiency.

3. Propose optimal single-pass solution

Iterate through the array once, keeping track of the most recent index of word1 and word2. When you see either word, update its last seen index and if the other word has been seen, compute the distance and update the minimum.

4. Analyze complexity

State that the algorithm runs in O(n) time and uses O(1) extra space, which is optimal because you must look at each element at least once in the worst case.

5. Handle edge cases and extensions

Discuss what happens if one word appears many times, if the words are the same (though problem says distinct), or if the array is empty. Also mention the preprocessing approach for multiple queries.

Key Points to Mention

  • Single-pass linear scan with two pointers (last seen indices)
  • Time complexity O(n) and space complexity O(1)
  • Updating minimum distance only when both words have been seen
  • Handling edge cases: words at beginning/end, large arrays, repeated words
  • Alternative for multiple queries: preprocess positions and binary search
  • Clarifying assumptions: distinct words, both present, distance as absolute index difference

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