WORLD 9
DESIGN
Build your own data structure, with every operation in constant time: a stack that knows its minimum, a cache.
STAGE 0 Design tutorial
0:00 / 0:00
The move
You get a blueprint: a class with a few methods and a promised cost for each. Snap a helper part onto the plain data (a second value, a map from key to node, a heap) so every call stays fast.
- Spot it
- The problem says design or implement a class, and each method must run in O(1) or O(log n), often on average.
- Cost
- Fast calls are paid for with extra memory, usually one entry per item: O(n) space.
15 STAGES Design problems
☆☆☆☆☆ Clear 5 to finish this world.
MEDIUM1:26Min Stack
DesignLC 155▶ START
EASY1:42Implement Queue using Stacks
DesignLC 232▶ START
MEDIUM1:42Binary Search Tree Iterator
DesignLC 173▶ START
MEDIUM1:34LRU Cache
Hash map + linked listLC 146▶ START
HARD1:40LFU Cache
DesignLC 460▶ START
MEDIUM1:31Insert Delete GetRandom O(1)
Hash mapLC 380▶ START
MEDIUM1:39Add and Search Words
TrieLC 211▶ START
HARD1:36Find Median from Data Stream
HeapsLC 295▶ START
MEDIUM1:39Time Based Key-Value Store
Binary searchLC 981▶ START
HARD1:42Merge k Sorted Lists
HeapLC 23▶ START
MEDIUM1:45Design Twitter
HeapLC 355▶ START
EASY1:28Kth Largest Element in a Stream
HeapLC 703▶ START
EASY1:41Last Stone Weight
HeapLC 1046▶ START
MEDIUM1:37Detect Squares
Hash mapLC 2013▶ START
MEDIUM1:40K Closest Points to Origin
HeapLC 973▶ START