← Uber Interview Insights

Uber·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Coding screen for a frontend role at Uber. One question, LC 380. The interviewer was apparently on their bed during the call, which was a vibe I did not expect.

Questions Asked (1)

Q1

Implement a data structure that supports insert, delete, and get random element, all in average O(1) time.

Algorithms & Data Structures
Author's notes

Classic combo of a hashmap and an array.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Combine a hash map and a dynamic array to achieve O(1) average time for insert, delete, and getRandom. The hash map stores value-to-index mappings, while the array stores the elements; deletion swaps the target with the last element and pops, updating the map accordingly.

Pro tip: Mention that this design is exactly what powers features like random ad selection or shuffle bags in games, showing you understand real-world applications. Also, clarify that O(1) is average-case due to hash collisions, and discuss how you'd handle duplicates if the problem requires it.

1. Clarify requirements and constraints

Ask whether duplicates are allowed, whether the data structure needs to support other operations, and confirm that average O(1) is acceptable. This shows you think about edge cases before coding.

2. Choose the right data structures

Select a hash map for O(1) lookups and a dynamic array for O(1) random access. Explain that the map will store value-to-index mappings, and the array will store the actual elements.

3. Design insert and getRandom operations

For insert, append to the array and add the index to the map. For getRandom, generate a random index and return the array element at that index.

4. Design delete operation with swap-and-pop

To delete a value, retrieve its index from the map, swap it with the last element in the array, update the map for the swapped element, then pop the last element and remove the deleted value from the map.

5. Analyze complexity and edge cases

Confirm that all operations are O(1) average time. Discuss handling of duplicates (e.g., using a set of indices per value) and empty structure edge cases.

Key Points to Mention

  • Hash map provides O(1) average lookup for value-to-index mapping.
  • Dynamic array provides O(1) random access for getRandom.
  • Swap-and-pop technique ensures O(1) deletion by avoiding shifting elements.
  • Updating the hash map after swapping is crucial to maintain correct indices.
  • Average O(1) vs worst-case O(n) due to hash collisions; mention this nuance.
  • Handling duplicates may require a map of value to a set of indices, which changes complexity.

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