Challenges
Interview-style challenges: solve a problem with a specific pattern, run tests in the browser, get feedback and discuss with others.
Design patterns
- Undo and redo in a text editor medium · typescript, javascript, python, csharp, java, go
Editor operations as commands with execute() and undo(), a history with undo and redo, macros undone in one step and a limit on remembered changes.
- Subscription lifecycle as a state machine medium · typescript, javascript, python, csharp, java, go
A SaaS subscription moves through trial, active, past-due and cancelled. Every state is a separate class that decides about transitions itself – no ever-growing switch.
- Exchange-rate caching proxy medium · typescript, javascript, python, csharp, java, go
Two proxies in front of a slow bank API – a caching one with an entry lifetime and a lazy one that connects only on first use. They share one interface, so they compose.
- Pricing formula visitor hard · typescript, javascript, python, csharp, java, go
A pricing formula tree and three operations on it – evaluation, printing and simplification – as visitors. A new operation leaves the node classes untouched.
- Lazy iterator over a paged API medium · typescript, javascript, python, csharp, java, go
Orders from an API that returns pages with a cursor, exposed as one collection – lazy page fetching, skipping empty pages, protection against a looping cursor and the native iteration protocol of…
- HTTP request builder easy · typescript, javascript, python, csharp, java, go
A fluent builder for an immutable HTTP request – defaults, header normalisation, validation in build() and a reusable builder.
- Game checkpoints easy · typescript, javascript, python, csharp, java, go
Saving and restoring a hero's state with Memento – immutable snapshots without shared lists, a caretaker with limited capacity and protection against loading someone else's save.
- Expense approval chain easy · typescript, javascript, python, csharp, java, go
An expense travels through links – receipt check, team lead, manager, director – until someone approves or rejects it. Chain of Responsibility with pluggable links.
- Catalog specifications medium · typescript, javascript, python, csharp, java, go
Promotion rules as small objects combined with and, or and not – the Specification pattern from DDD, custom rules and catalog search.
- Order observer medium · csharp, typescript
An order notifies subscribers when its status changes; subscriptions can be cancelled and an audit log records transitions.
- Discount strategy medium · python, typescript
Interchangeable discount algorithms in a checkout: percentage, threshold and "best of", swapped at runtime.
- Notification factory easy · typescript, javascript
Implement Factory Method: every notification service decides which channel (e-mail, SMS, push) it creates.
Architecture
- Circuit breaker for a payment gateway hard · typescript, javascript, python, csharp, java, go
A circuit breaker with closed, open and half-open states, an injected clock, a trial-success threshold and a business-error filter – so a payment gateway outage does not take the whole shop down.
- Inventory with CQRS – separate write and read models medium · typescript, javascript, python, csharp, java, go
Warehouse commands validated on their own write model, events on a bus and a projection building a read model with a low-stock report. The read model can be rebuilt from events alone.
- Event-sourced bank account hard · typescript, javascript, python, csharp, java, go
An account aggregate whose state comes only from replaying events, an event store with optimistic concurrency and a repository that saves only new facts. Queries about past state come for free.
Algorithms
- Split a hashtag into words medium · typescript, javascript, python, csharp, java, go
Can a string without spaces (e.g. a hashtag) be split into dictionary words? Dynamic programming instead of exponential backtracking.
- Two items for the budget easy · typescript, javascript, python, csharp, java, go
An interview classic – find two different positions in a price list that add up to exactly the given amount. One pass with a map instead of two nested loops.
- Search suggestions with a trie medium · typescript, javascript, python, csharp, java, go
A search box suggests the most popular phrases that start with the typed prefix. A prefix tree (trie), popularity counters and a deterministic order.
- Most frequent tags medium · typescript, javascript, python, csharp, java, go
Count occurrences and pick the k most popular tags, breaking ties alphabetically. A counter map plus a heap of size k, or sorting.
- Rate limiter – token bucket medium · typescript, javascript, python, csharp, java, go
Implement the token bucket algorithm – the same one API gateways and reverse proxies use. Lazy refilling, fractional tokens and an injected clock.
- Spiral matrix easy · typescript, javascript, python, csharp, java, go
Read the elements of a matrix clockwise, from the outside to the centre. A task about keeping boundaries in check rather than about a clever algorithm.
- Sliding window maximum hard · typescript, javascript, python, csharp, java, go
For every window of k consecutive measurements report the largest value – in linear time, regardless of k. A monotonic queue on a double-ended queue (deque).
- Serialize a binary tree hard · typescript, javascript, python, csharp, java, go
Write a binary tree to a string and rebuild it – with empty subtrees, negative numbers and trees thousands of levels deep. Format design, BFS and the recursion trap.
- Search in a rotated array medium · typescript, javascript, python, csharp, java, go
Someone "turned" a sorted array at an unknown point. Find an element in O(log n) – binary search that recognises the sorted half at every step.
- Rotate an image by 90° easy · typescript, javascript, python, csharp, java, go
Rotate a square pixel matrix 90° clockwise – in place, without a copy. Transpose and mirror, or swap elements four at a time.
- Retry with exponential backoff easy · typescript, javascript, python, csharp, java, go
A function that retries a failed operation after 100, 200, 400… ms, with a cap and an error filter. The sleep function is injected, so tests never wait a millisecond.
- Product of all except self medium · typescript, javascript, python, csharp, java, go
For every position compute the product of the other elements – without division and in linear time. Prefix and suffix products, plus zeros.
- Number of islands medium · typescript, javascript, python, csharp, java, go
Count connected land areas on a map made of a character grid. Graph search (BFS/DFS) over cells – and the trap of deep recursion on a large map.
- Stack with O(1) minimum easy · typescript, javascript, python, csharp, java, go
Design a stack that, besides push, pop and top, returns its smallest element in constant time. A question about the memory–time trade-off.
- Merge intervals medium · typescript, javascript, python, csharp, java, go
Join overlapping and touching time intervals into disjoint blocks. Sorting plus a single pass – and a few traps with intervals nested inside others.
- Minimum number of rooms medium · typescript, javascript, python, csharp, java, go
How many conference rooms are needed for all the meetings to take place? A sweep line over time or a heap of end times.
- LRU cache medium · typescript, javascript, python, csharp, java, go
A fixed-capacity cache that evicts the least recently used entry when full. get and put in O(1) – a map plus a doubly linked list.
- Longest stretch without repeats medium · typescript, javascript, python, csharp, java, go
Find the longest contiguous part of a string in which no character repeats. A sliding window with a last-seen map – in a single pass.
- Longest increasing subsequence hard · typescript, javascript, python, csharp, java, go
Pick the longest strictly increasing subsequence from a series of measurements – and return it, not just its length. The classic O(n²) DP, then "patience sorting" with binary search in O(n log n).
- Read a value by JSON path easy · typescript, javascript, python
Our own `get(obj, 'orders[1].items[0].sku', default)` – parsing a simple path, telling "missing" from `null` and validating the syntax.
- Group anagrams easy · typescript, javascript, python, csharp, java, go
Words made of the same letters go into one group. An exercise in choosing a good map key – and in the order of results.
- Shortest path in a maze medium · typescript, javascript, python, csharp, java, go
A warehouse robot looks for the shortest route on a grid with obstacles. BFS in an unweighted graph – and why breadth-first rather than depth-first.
- Flatten a nested object easy · typescript, javascript, python
Turn a nested JSON object into a flat path → value map (e.g. for a CSV export or a config diff). Recursion or an explicit stack, leaves and empty containers.
- Your own EventEmitter easy · typescript, javascript, python
Write a simplified version of Node.js `EventEmitter` – on, once, off, emit and the special `error` event. The Observer pattern in practice, with the traps of modifying the list during emission.
- Edit distance (Levenshtein) hard · typescript, javascript, python, csharp, java, go
How many insertions, deletions and substitutions separate two strings? Dynamic programming on a 2D table, then saving memory down to a single row.
- Shortest delivery times (Dijkstra) hard · typescript, javascript, python, csharp, java, go
A network of logistics hubs with one-way routes of different travel times. Compute the shortest travel time from the warehouse to every hub – Dijkstra's algorithm with a heap that some languages…
- Debounce and throttle medium · typescript, javascript
Two classic frontend higher-order functions – debounce (call after silence) and throttle (at most once per period) – with cancel, flush, preserved this and injected timers.
- Consistent hashing ring hard · typescript, javascript, python, csharp, java, go
Spread cache keys over servers so that adding or removing a server moves only a small share of keys. A ring with virtual nodes and binary search.
- Change with the fewest coins medium · typescript, javascript, python, csharp, java, go
A vending machine gives change in unusual denominations and wants to use as few coins as possible. Greedy fails here – dynamic programming is needed.
- Module build order medium · typescript, javascript, python, csharp, java, go
A monorepo has modules that depend on other modules. Find a build order or detect a cycle – topological sorting with Kahn's algorithm.
- Balanced brackets easy · typescript, javascript, python, csharp, java, go
Check whether the round, square and curly brackets in a code fragment are properly nested. The textbook use of a stack.
- Async task pool with a limit medium · typescript, javascript
Run thousands of async tasks, but no more than N at a time – as when downloading files or calling a rate-limited API. Promises, result order and stopping at the first error.
Quizzes
- Design patterns – basics Quiz
Six questions about classic GoF patterns: groups, intent and differences.