Skip to content

Lesson 25 of 27Practice and polish

Multi-Part Practical Problems

Solve specs revealed in levels, like an in-memory database that gains scans, TTLs and backups, by reading fast and designing for the next change.

13 min read0/4 questions

Some coding rounds do not hand you a puzzle. They hand you a spec: "Build an in-memory database that supports set, get and delete." You build it, the tests pass, and a new section appears: "Now add prefix scans." Then: "Now every operation takes a timestamp, and values can expire." Then: "Now support backup and restore." Each level builds on the code you already wrote, so a shortcut in level 1 becomes a rewrite in level 3. This format rewards a different skill from the classic algorithm round: reading a long spec quickly, choosing a data model that bends instead of breaks, and keeping your code clean while a timer runs. It is also the closest thing in interviewing to a normal week at work.

The format

The best-known example is CodeSignal's Industry Coding Framework (ICF), used by a number of companies as an online assessment for mid-level and senior roles. As CodeSignal describes it at the time of writing (late 2026), it is a single task split into four levels over about 90 minutes, with automated tests for each level. Typical tasks are an in-memory database, a banking system, a file storage service or a task queue. Formats, timing, scoring and the rules for when the next level unlocks change, and companies can configure their own versions, so check CodeSignal's current candidate docs and whatever the recruiter sends you before you sit it.

Live practical rounds follow the same shape. Candidates commonly report this style at fintech companies such as Stripe, Ramp and Coinbase: a realistic multi-part problem, often with an interviewer adding the next part when you finish the current one. Treat these reports as a description of the genre, not of any company's current process.

Whatever the platform, the levels usually escalate like this:

LevelWhat it addsWhat it tests
1Basic CRUD operations on a simple modelCan you read a spec and get the contract exactly right?
2Queries over the data: scans, filters, sorting, top-nCan you extend without breaking level 1?
3Time: timestamps, TTLs, scheduled actions, historyDoes your data model admit a new dimension?
4State over time: backup and restore, undo, merges, transfersCan you copy, roll back and reason about edge cases under pressure?

Few candidates finish all four levels. Scoring typically rewards each passing test, so a clean, fully passing level 3 beats a half-working level 4.

Reading a long spec fast

A level spec is often a page of prose with method signatures buried inside. Do not read it like a story. Extract a checklist before you type, in this order:

  1. Operations. Every method name and its parameters, exactly as spelled. Tests call them by name.
  2. Return contract. What each one returns on success, and what it returns on "not found". None, "", False and an exception are four different answers, and the tests will check which one you chose.
  3. Output format. If a method returns a string such as "name(Ada), city(London)", copy the format character by character. Spacing and ordering mistakes fail tests that your logic would pass.
  4. Ordering rules. "Sorted by field name", "by balance descending, ties by account id": these are where hidden tests cluster.
  5. Error cases. Missing keys, duplicate creates, transfers to self, insufficient funds.
  6. Hints about the future. A field you do not need yet, such as a timestamp argument that is "ignored in this level", is the spec telling you what comes next.
Put it in order5 steps

You have just opened level 1 of a practical task. Put these first steps in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

Design for the next level, not the last one

You cannot see level 3 while you write level 1. You can still make choices that keep it cheap to add. Three habits do most of the work.

Put every rule in one place. If "is this field visible?" is decided in one helper, adding expiry in level 3 changes one function. If every method reads the dict directly, level 3 changes every method, and you will miss one.

Make simple versions call general ones. Once timestamps appear, rewrite get(key, field) as get_at(key, field, None). Two code paths that must agree will drift; one path cannot.

Store a small record, not a bare value, once there is a second attribute. A bare string becomes Entry(value, expires_at) the moment expiry appears. A NamedTuple or frozen dataclass is immutable, which also makes level 4 copies safe.

What you should not do is build for imagined levels: generic plugin systems, abstract base classes, an event bus. That costs minutes you need, and the real level 3 rarely matches what you guessed. The aim is code that is easy to change, not code that already handles everything.

How the data model grows across levels
  1. backups: list of (time, snapshot)level 4
  2. Entry(value, expires_at)level 3
  3. _live(key, ts) helperlevels 2 and 3
  4. data: dict[key, dict[field, value]]level 1

Level 1 needs only a dict of dicts. A record per key, a value per field. setdefault creates records lazily.

1/4

Worked example, levels 1 and 2

Here is level 1 (set, get, delete) and level 2 (scan, scan_by_prefix) written the way you would under time. The tests at the bottom are the kind you should write yourself as you go: one or two asserts per operation, including the not-found case.

Pythondb_levels_1_2.py
class InMemoryDB: """Levels 1 and 2: records are key -> {field: value}.""" def __init__(self) -> None: self.data: dict[str, dict[str, str]] = {} # Level 1 def set(self, key: str, field: str, value: str) -> None: self.data.setdefault(key, {})[field] = value def get(self, key: str, field: str) -> str | None: return self.data.get(key, {}).get(field) def delete(self, key: str, field: str) -> bool: record = self.data.get(key) if record is None or field not in record: return False del record[field] if not record: del self.data[key] # no empty records left behind return True # Level 2 def scan(self, key: str) -> list[str]: return self.scan_by_prefix(key, "") def scan_by_prefix(self, key: str, prefix: str) -> list[str]: record = self.data.get(key, {}) return [f"{f}({v})" for f, v in sorted(record.items()) if f.startswith(prefix)] db = InMemoryDB()# Level 1 testsdb.set("user1", "name", "Ada")db.set("user1", "city", "London")assert db.get("user1", "name") == "Ada"assert db.get("user1", "age") is Noneassert db.get("nobody", "name") is Noneassert db.delete("user1", "city") is Trueassert db.delete("user1", "city") is False# Level 2 testsdb.set("user1", "nick", "ada99")db.set("user1", "email", "ada@example.com")assert db.scan("user1") == ["email(ada@example.com)", "name(Ada)", "nick(ada99)"]assert db.scan_by_prefix("user1", "n") == ["name(Ada)", "nick(ada99)"]assert db.scan("nobody") == []print("levels 1-2 pass")
Output
Press Run (⌘ Enter) to see what happens.

Small choices worth noticing: scan is scan_by_prefix with an empty prefix, so the sort and format live in one place. delete removes empty records, which matters later when a level asks "how many keys are there?" And every not-found path returns the same kind of thing for the same method: None for get, False for delete, [] for scans.

Worked example, levels 3 and 4

Level 3 says every operation gains a _at version with a timestamp, and set_at can take a TTL: a value set at time 10 with TTL 5 is visible at times 10 to 14 and gone at 15. Level 4 adds backup(ts), which saves the live state and returns the number of non-empty records, and restore(ts, ts_to_restore), which restores the latest backup taken at or before ts_to_restore. The twist that trips people: a restored value keeps the remaining lifetime it had at backup time, counted from the restore time.

Pythondb_levels_1_4.py
from typing import NamedTuple class Entry(NamedTuple): value: str expires_at: int | None # None means it never expires class InMemoryDB: """Levels 1 to 4. Level 3 changed the stored value into an Entry.""" def __init__(self) -> None: self.data: dict[str, dict[str, Entry]] = {} self.backups: list[tuple[int, dict[str, dict[str, Entry]]]] = [] # One place decides what is visible at a time. ts=None means "ignore time". def _live(self, key: str, ts: int | None) -> dict[str, Entry]: record = self.data.get(key, {}) if ts is None: return record return {f: e for f, e in record.items() if e.expires_at is None or ts < e.expires_at} # Level 1 (untimed calls reuse the timed ones) def set(self, key, field, value): self.set_at(key, field, value, None) def get(self, key, field): return self.get_at(key, field, None) def delete(self, key, field): return self.delete_at(key, field, None) # Level 2 def scan(self, key): return self.scan_by_prefix_at(key, "", None) def scan_by_prefix(self, key, prefix): return self.scan_by_prefix_at(key, prefix, None) # Level 3 def set_at(self, key, field, value, ts, ttl=None): expires_at = None if ttl is None else ts + ttl self.data.setdefault(key, {})[field] = Entry(value, expires_at) def get_at(self, key, field, ts): entry = self._live(key, ts).get(field) return None if entry is None else entry.value def delete_at(self, key, field, ts): if field not in self._live(key, ts): return False del self.data[key][field] if not self.data[key]: del self.data[key] return True def scan_at(self, key, ts): return self.scan_by_prefix_at(key, "", ts) def scan_by_prefix_at(self, key, prefix, ts): live = self._live(key, ts) return [f"{f}({e.value})" for f, e in sorted(live.items()) if f.startswith(prefix)] # Level 4 def backup(self, ts): snapshot = {} for key in self.data: live = self._live(key, ts) if live: # Store remaining lifetime, not the absolute expiry. snapshot[key] = { f: Entry(e.value, None if e.expires_at is None else e.expires_at - ts) for f, e in live.items() } self.backups.append((ts, snapshot)) return len(snapshot) def restore(self, ts, ts_to_restore): chosen = None for backup_ts, snapshot in self.backups: # backups arrive in time order if backup_ts <= ts_to_restore: chosen = snapshot if chosen is None: raise ValueError("no backup at or before that time") self.data = { key: {f: Entry(e.value, None if e.expires_at is None else ts + e.expires_at) for f, e in fields.items()} for key, fields in chosen.items() } db = InMemoryDB()# Levels 1 and 2 still pass unchangeddb.set("user1", "name", "Ada")assert db.get("user1", "name") == "Ada"assert db.scan("user1") == ["name(Ada)"]assert db.delete("user1", "name") is True and db.get("user1", "name") is None # Level 3: a TTL of 5 set at t=10 is visible for t in [10, 15)db.set_at("s", "token", "abc", 10, ttl=5)db.set_at("s", "user", "ada", 11)assert db.get_at("s", "token", 14) == "abc"assert db.get_at("s", "token", 15) is Noneassert db.scan_at("s", 16) == ["user(ada)"]assert db.delete_at("s", "token", 20) is False # already expired # Level 4: the backup keeps 3 units of life left on the tokendb.set_at("s", "token", "xyz", 20, ttl=5) # expires at 25assert db.backup(22) == 1 # one non-empty recorddb.set_at("s", "user", "bob", 23)db.restore(30, 22) # roll back to the t=22 backupassert db.get_at("s", "token", 32) == "xyz" # restored at 30 with 3 leftassert db.get_at("s", "token", 33) is Noneassert db.get_at("s", "user", 30) == "ada"print("levels 1-4 pass")
Output
Press Run (⌘ Enter) to see what happens.

Look at how little of level 1 and 2 changed. The four original methods became one-line wrappers, and all of the time logic sits in _live, set_at and the level 4 methods. That is the payoff from routing reads through one helper early.

Two details in level 4 are classic hidden-test targets. First, expires_at - ts converts an absolute expiry into a remaining lifetime, and restore converts it back with the new time. Storing absolute expiry in the backup would make every restored TTL wrong. Second, the backup is built from new dicts and immutable entries, so later writes cannot leak into it.

Predict the outputPython

What does this print?

data = {"a": {"x": "1"}}
backup = dict(data)
data["a"]["x"] = "2"
print(backup["a"]["x"])
Need a nudge? Hints walk you through it.
Match the pairs0/5 matched

Match each new level requirement to the change it forces in your data model.

Choose an item, then its match on the other side.

Test-driven speed

Automated tests are your score, so run them constantly.

  • Run after every operation, not after the whole level. A failing test with two new methods is a two-place search. With eight, it is a debugging session.
  • Read the failing assertion before the code. "Expected ['a(1)', 'b(2)'], got ['b(2)', 'a(1)']" says sorting. "Expected None, got ''" says contract. Most level failures are format or contract mismatches, not logic.
  • Write your own asserts for the edges the spec mentions and the visible tests do not cover, because hidden tests usually cover exactly those: not found, duplicates, empty results, ties in sort order, boundary times such as ts == expires_at.
  • Take partial credit deliberately. If a level is mostly passing and one awkward test remains with 20 minutes left, read the next level. Its first tests are often easier than the last test of the current one. Where the platform lets you move on, the score usually counts tests passed, not levels completed.
Quick check
The spec says a value set at time 10 with TTL 5 'is available for 5 time units'. Your get_at uses ts <= expires_at. A hidden test fails. What is the most likely cause?
Need a nudge? A hint rules out a wrong answer.

Clean code under a timer

Practical rounds are often reviewed by a human afterwards, and live versions are watched as you type. Messy code that passes can still cost you.

  • Name things from the spec. If the spec says "record" and "field", your variables say record and field, not d and k2.
  • One contract per method. Pick the not-found value the spec gives and use it on every path. A get that returns None on a missing key but raises KeyError on a missing field is a bug waiting for a hidden test.
  • No dead branches. Delete the commented-out level 2 attempt. Unused parameters with a note ("ts reserved for level 3") are fine; abandoned code is not.
  • Small helpers over long methods. _live, _format, _require_account. Each later level then reads like a short list of steps.
  • Refactor between levels, not during. When a level passes, spend two minutes on the obvious duplication before you read the next spec. Refactoring while tests fail mixes two kinds of change, and you lose track of which one broke things.
Key terms
Industry Coding Framework
CodeSignal's multi-level practical assessment format: one task, extended in levels, scored by automated tests. Check current docs for timing and rules.
level
One stage of a practical task that adds requirements on top of the code from earlier stages.
return contract
The exact value a method returns for each outcome, including not found and invalid input.
TTL
Time to live: how long a value stays visible after it is set before it counts as expired.
half-open interval
A range that includes its start and excludes its end, such as [10, 15).
snapshot
A copy of state at one moment that later writes cannot change.
shallow copy
A copy of the outer container only, whose nested objects are still shared with the original.