← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Uber ML engineer interview with a backtracking problem. Pretty standard coding round, nothing too exotic, but the deduplication logic is the part that trips people up if you haven't seen it before.

Questions Asked (1)

Q1

Given a list of integers that may contain duplicates, return all unique permutations.

Algorithms & Data Structures
Author's notes

The core trick is sorting first and then skipping a number at the current recursion level if it's identical to the previous one and that previous one wasn't used.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use backtracking with sorting and a used array to generate permutations while skipping duplicates at the same recursion level. Alternatively, use a frequency map to build unique permutations by choosing each distinct number once per position. Discuss time complexity O(n * n!) and space O(n) for recursion.

Pro tip: Mention that sorting and skipping duplicates is a common pattern for combination/permutation problems, and that using a frequency map can be more efficient when there are many duplicates. Also, note that the output size is n! in the worst case, so the algorithm is optimal in terms of output size.

1. Clarify and Sort

Confirm that the input list may contain duplicates and that we need unique permutations. Sort the list to bring duplicates together, which simplifies duplicate skipping.

2. Choose Backtracking Strategy

Decide between using a used array with sorting or a frequency map. Explain the trade-offs: used array is simpler but requires sorting; frequency map avoids sorting and can be more efficient with many duplicates.

3. Implement Backtracking

Recursively build permutations by choosing an unused element at each step. If using used array, skip duplicates by checking if the previous identical element is unused. If using frequency map, iterate over distinct keys and decrement counts.

4. Analyze Complexity

State that time complexity is O(n * n!) in the worst case (all unique) and space is O(n) for recursion and used array. Mention that the number of unique permutations can be less with duplicates.

5. Test and Optimize

Walk through a small example with duplicates, e.g., [1,1,2], to verify correctness. Discuss potential optimizations like pruning or using iterative approaches if needed.

Key Points to Mention

  • Backtracking with sorting and used array to skip duplicates
  • Alternative frequency map approach for handling duplicates
  • Time complexity O(n * n!) and space O(n)
  • Duplicate skipping condition: if used[i] or (i > 0 and nums[i] == nums[i-1] and not used[i-1])
  • Handling edge cases: empty list, single element, all duplicates
  • Output size can be large, so algorithm is optimal in terms of output size

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