Skip to main content

πŸ—οΈ Design

Design problems test how you combine data structures. The trick is meeting time-complexity requirements on every operation simultaneously β€” usually by chaining a hash map with a doubly-linked list or heap.

This category contains 11 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • LRU Cache β€” Hash map + doubly-linked list for O(1)O(1) get & put.
  • LFU Cache β€” Hash + frequency buckets (lists or heap).
  • Iterator β€” Encapsulate state; provide hasNext / next lazily.
  • Range Sum (Immutable / Mutable / 2D) β€” Prefix sums, Fenwick tree, segment tree.
  • Time-based Key-Value Store β€” Hash map β†’ list, binary search on timestamps.
  • Min Stack β€” Auxiliary stack of running mins.

⚠️ Common Pitfalls​

  • Forgetting the doubly-linked list β€” singly is O(n)O(n) for the remove step in LRU.
  • Not clarifying complexity targets up front; over- or under-engineering.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

  • Designing Data-Intensive Applications β€” Kleppmann β€” For real-world scale (beyond LeetCode)
  • Cracking the Coding Interview β€” Ch. 7 (OO Design), Ch. 9 (System Design)

🌐 Articles & References​


πŸ’» All Design Problems​