PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to design an efficient in-memory LRU cache and apply concurrency control, covering eviction semantics, capacity management, key updates, and synchronization for thread safety.

  • Medium
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Design a single-machine LRU cache

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Design an in-memory LRU cache for a single machine using a hash map and a doubly linked list to support O( 1) get and put. Explain how you handle capacity, eviction, and key updates. Then make your design thread-safe: discuss lock granularity (global lock vs. per-bucket/segmented locks), readers–writer locks, lock-free alternatives, and how you would prevent race conditions and ensure memory safety. Analyze time and space complexity and outline major pitfalls.

Quick Answer: This question evaluates a candidate's ability to design an efficient in-memory LRU cache and apply concurrency control, covering eviction semantics, capacity management, key updates, and synchronization for thread safety.

Simulate get and put for an LRU cache with fixed capacity.

Examples

Input: (2, [('put', 1, 1), ('put', 2, 2), ('get', 1), ('put', 3, 3), ('get', 2), ('get', 3)])

Expected Output: [1, -1, 3]

Explanation: Evicts least recently used.

Input: (0, [('put', 1, 1), ('get', 1)])

Expected Output: [-1]

Explanation: Zero capacity.

Input: (1, [('put', 1, 1), ('put', 1, 2), ('get', 1)])

Expected Output: [2]

Explanation: Update existing key.

Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Validate a Shopping Cart - DoorDash (medium)
  • Calculate Driver Payments - DoorDash (medium)
  • Implement Timeout Refund Workflow - DoorDash (medium)
  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)