← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

DoorDash SWE coding round focused on a buggy data structure implementation, basically a variant of the insert-delete-getRandom problem dressed up in DoorDash branding. The debugging angle was a nice twist compared to the usual 'write it from scratch' format.

Questions Asked (2)

Q1

You're given a buggy implementation of a data structure that supports insert, delete, and pickRandom (uniform O(1) random selection). Find and fix the functional bugs, specifically issues in the swap-with-last-element pattern including the edge case where the element being removed is already the last one.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the underlying problem well enough but staring at someone else's broken code is a different beast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, explain the standard array + hashmap design for O(1) insert, delete, and pickRandom, emphasizing the swap-with-last pattern. Then, walk through the buggy code to identify functional bugs, focusing on the edge case where the removed element is already the last element. Finally, propose fixes and verify correctness with test cases.

Pro tip: When fixing the swap-with-last pattern, always check if the index of the element to remove equals the last index; if so, skip the swap and just pop. Also, remember to update the hashmap for the swapped element before removing the target.

1. Explain the intended design

Describe how an array stores elements for O(1) random access and a hashmap maps values to their indices for O(1) lookup. Insert appends to the array and adds to the map; delete swaps the target with the last element, updates the map, and pops; pickRandom returns a random array element.

2. Identify the buggy areas

Scan the code for issues in the swap-with-last logic, such as not handling the case when the target is the last element, incorrect index updates in the hashmap, or missing updates when swapping.

3. Analyze the edge case

Focus on the scenario where the element to delete is already at the last index. In this case, swapping with itself is redundant and can cause errors if not handled; the correct action is to simply remove it from the array and map.

4. Propose and implement fixes

Modify the delete method to check if the target index is the last index; if so, skip the swap. Otherwise, swap with the last element, update the hashmap for the swapped element, then remove the last element from both array and map.

5. Test and verify

Walk through test cases: deleting the last element, deleting a middle element, deleting the only element, and ensuring pickRandom remains uniform. Confirm O(1) time complexity for all operations.

Key Points to Mention

  • Array + hashmap design for O(1) operations
  • Swap-with-last pattern for O(1) deletion
  • Edge case: removing the last element (no swap needed)
  • Updating hashmap indices after swap
  • Handling deletion when only one element exists
  • Maintaining uniform randomness in pickRandom

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

Q2

Beyond the logic errors, what non-functional bugs exist in the implementation? Think about exception handling and thread-safety.

System DesignTechnical Trade-offs
Author's notes

Thread-safety part tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Acknowledge that non-functional bugs like poor exception handling and thread-safety issues can be as critical as logic errors, especially in production systems. Systematically categorize the types of non-functional bugs, explain their impact, and propose mitigation strategies. Emphasize a proactive approach to identifying and preventing such issues through code reviews, testing, and design patterns.

Pro tip: Relate non-functional bugs to real-world consequences like service outages or data corruption, and mention specific tools or practices (e.g., static analysis, concurrency testing) you've used to catch them early.

1. Define non-functional bugs

Clarify that non-functional bugs pertain to quality attributes like reliability, security, and performance, not just incorrect output. Give examples such as unhandled exceptions, race conditions, and resource leaks.

2. Analyze exception handling

Discuss common exception handling pitfalls: swallowed exceptions, overly broad catches, missing finally blocks, and lack of logging. Explain how these can mask failures and complicate debugging.

3. Analyze thread-safety

Identify thread-safety issues: shared mutable state without synchronization, non-atomic operations, deadlocks, and race conditions. Mention the importance of immutability, locks, and concurrent data structures.

4. Assess impact and prioritize

Explain how these bugs can lead to intermittent failures, data corruption, or security vulnerabilities. Prioritize based on severity and likelihood, considering the system's concurrency model and error tolerance.

5. Propose solutions and prevention

Suggest fixes like proper exception propagation, using thread-safe collections, and adopting design patterns (e.g., immutable objects). Recommend preventive measures: code reviews, static analysis, stress testing, and monitoring.

Key Points to Mention

  • Swallowed exceptions and empty catch blocks
  • Overly broad exception handling (e.g., catching Exception or Throwable)
  • Missing finally blocks for resource cleanup
  • Race conditions and data races due to unsynchronized access
  • Deadlocks from inconsistent lock ordering
  • Use of thread-safe data structures and synchronization primitives
  • Importance of logging and monitoring for non-functional issues
  • Testing strategies: unit tests with concurrency, stress tests, and fault injection

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