bigonotes
DSA: Patterns & PythonDesign Problems

Design Problems

LeetCode design problems, grouped by the data structure behind them.

7 notes · 46 min total

Questions0 of 32 done

Warm up with these before Phase 1.

Patterns

  1. 1Hashmap + Doubly Linked List (LRU and LFU)Pair a dict with a linked list to get O(1) lookup and O(1) reordering, the core of LRU and LFU caches.7 min
  2. 2Sliding Time Window: Deque, Ring Buffer and BucketsAnswer 'how many in the last N seconds' with a pruned deque, a fixed ring buffer or time buckets, and know what each costs.9 min
  3. 3Sorted Timestamps + Binary SearchKeep timestamps sorted and use bisect to answer range, 'as of time t' and per-bucket count queries in O(log n).5 min
  4. 4Heap with Lazy DeletionKeep a dict as the source of truth, push updates into a heap, and discard stale tops on read; plus k-way merge and ID pools.7 min
  5. 5Trie-Backed DesignUse a trie for prefix-shaped designs like autocomplete and file paths, and choose between ranking on write or on read.6 min
  6. 6Concurrency Primitives: Locks, Conditions and SemaphoresBuild a bounded blocking queue with a condition variable or semaphores, and spot check-then-act races in design follow-ups.6 min
  7. 7Hashmap State Modeling: Aggregates and Composite KeysModel design state with dicts: store running totals instead of history, key on tuples, and drop transient state once it is used.6 min