← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

One round at Uber for a software engineering role, basically just a single coding problem but they pushed hard on it. They wanted the full progression from brute force up to linear time, plus test cases, so it wasn't just 'write the solution and move on.'

Questions Asked (1)

Q1

Given a linked list where each node has a next pointer and a random pointer that can point to any node in the list (or null), write a deep copy of the list. Walk through a brute force approach, then optimize it, targeting O(n) time. Include test cases.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

They wanted the whole journey, not just the optimal answer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and walking through a brute force approach using a hash map to map original nodes to copies, then optimize to O(1) space by interleaving copied nodes and splitting the list. Emphasize time and space complexity trade-offs and discuss test cases including edge cases.

Pro tip: Mention that the interleaving approach modifies the original list temporarily but restores it, and discuss when the hash map approach might be preferable (e.g., if the list is immutable or thread-safety concerns). This shows awareness of real-world constraints.

1. Clarify and outline brute force

Confirm assumptions: random pointer can point to any node or null, list may be empty. Describe brute force: traverse original list, create a copy of each node and store mapping in a hash map, then set next and random pointers using the map.

2. Analyze brute force complexity

State time complexity O(n) and space complexity O(n) due to hash map. Note that this is acceptable but can be optimized for space.

3. Optimize to O(1) space

Explain the interleaving approach: insert copied nodes right after each original node, set random pointers for copies using original's random, then split the interleaved list into original and copy.

4. Walk through code and edge cases

Write pseudocode or code for the optimized approach, handling edge cases like empty list, single node, random pointer to null, and self-referencing random pointer.

5. Discuss test cases and trade-offs

List test cases: empty list, single node, multiple nodes with random pointers to various nodes including null. Compare approaches: hash map is simpler and doesn't modify original, interleaving is O(1) space but modifies original temporarily.

Key Points to Mention

  • Hash map approach: mapping original nodes to copies for O(n) time and O(n) space.
  • Interleaving approach: O(n) time and O(1) space by weaving copies into original list.
  • Edge cases: empty list, single node, random pointer to null, random pointer to self, random pointer to any node.
  • Time and space complexity analysis for both approaches.
  • Trade-offs: hash map is simpler and preserves original list; interleaving is more space-efficient but modifies original temporarily.
  • Test cases to verify correctness: compare deep copy by checking that no node is shared and random pointers are correctly replicated.

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