Pattern · 25 problems
Class Design Interview Problems
Design problems ask for a class, not a function. I list the methods and the cost I want from each, then choose structures.
Free: write the code and run it, no sign-up.
When I reach for it
- The statement describes a class with methods, not one function.
- Each method needs to be fast, and the structure decides how fast.
- Requirements arrive in stages.
Problems, easiest first
2 easy · 12 medium · 11 hard. Open one to read it, then write it in the free editor.
- Kth Largest Element in a StreameasyHeapsTrees
- Implement Queue using StackseasyStack
- Implement Trie (Prefix Tree)mediumTreesStrings
- Design Add and Search Words Data StructuremediumTreesStrings
- Encode and Decode StringsmediumStrings
- Design TwittermediumLinked ListsHeaps
- Detect SquaresmediumArrays & Hashing
- LRU CachemediumLinked ListsArrays & Hashing
- Min StackmediumStack
- Time Based Key-Value StoremediumBinary SearchArrays & Hashing
- Design Memory Allocatormedium
- In-Memory SQL Enginemedium
- Snack Bin Iterator — Flatten Nested ListsmediumStack
- Web CrawlermediumGraphsStrings
- Serialize and Deserialize Binary TreehardTreesBFS & DFS
- Find Median from Data StreamhardHeapsTwo Pointers
- Encrypt and Decrypt StringshardStringsArrays & Hashing
- GPU Credits Managerhard
- Design Excel Sum FormulahardGraphsStrings
- Carnival Concession Inventoryhard
- Cloudflare Rate Limiterhard
- Feature Flag Timeline Storehard
- Figma Document Bufferhard
- Pop-up Clinic Check-in Tablehard
- Robinhood Order Bookhard
The idea
Write down every method and the cost you want for it. Then pick the structure that delivers those costs, such as a hash map plus a list.
State the invariants. What must stay true after every call? Check them on the error paths too.
from collections import deque
class HitCounter:
def __init__(self):
self.hits = deque() # timestamps, oldest first
def hit(self, t):
self.hits.append(t)
def count(self, t):
while self.hits and self.hits[0] <= t - 300:
self.hits.popleft() # drop what has expired
return len(self.hits)Where it goes wrong
- Choosing a structure before listing what each method must do.
- Breaking an invariant on an error path.
- Skipping the questions: size limits, duplicates and thread safety.
Say this before you type. Say each method, the cost you want from it, and the structure that earns that cost.
Where Coco comes in
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.
Questions people ask
- How do I pick the data structure?
- Start from the slowest operation you cannot afford. Choose the structure that makes it cheap, then check what that choice does to the others.
- Do I write the whole class at once?
- No. Get one method working against the example, then add the next. Staged requirements reward small steps.
Meet these next
Fin and Coco are characters, not people. strongyes.io is independent. Leo builds it with AI agents.
