Pattern

Data structure design

Build a small class that supports a fixed set of operations, each with its own required time complexity.

What it is

Design questions hand you an interface — a list of method names and the time complexity each must meet — and ask you to implement it from scratch. There is no single algorithm; the skill is picking the right combination of built-in structures (hash maps, heaps, linked lists, arrays, tries) so that every required operation, not just the common one, hits its target. Many of these are really "which structure gives O(1)/O(log n) for this specific operation" puzzles stacked two or three deep.

When it applies

Tells in the problem

The classic mistake

Under-designing the eviction or ordering logic is the usual failure mode: reaching for a single hash map and believing a sorted() call or a linear scan over its values will keep things fast enough, only to have every operation degrade to O(n) once the interface is checked against its stated complexity. This usually happens because the map correctly answers the "everyday" query and the candidate stops there, without checking every method against its own complexity requirement. Before writing code, write down each method and the structure that satisfies it in isolation — if one structure can't cover a method, you need a second structure kept in sync with the first (e.g. a hash map for lookup plus a linked list for order), not a cleverer way to search the first one.

Questions to start with

All 18 data structure design questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.