In-memory database
Anthropic and Airbnb candidates report the same first coding round: an online test on CodeSignal, one problem in four levels, 90 minutes on the clock (4 reports). When it starts, the screen shows a problem like this one, and only its first level:
Build a simple in-memory database. Its requirements grow level by level, and each level opens only when every test so far passes, so plan your code for change.
Level 1. The database holds records. Each record has a unique key, and holds fields, each with a value. Keys, fields and values are all strings.
set(key, field, value)storesvalueunderfieldin the recordkey. It creates the record if there isn't one, and replaces the value if the field already has one.get(key, field)returns the value, orNoneif the record or the field doesn't exist.delete(key, field)removes the field. It returnsTrueif the field existed, andFalseif it didn't.
Call Returns set("user1", "name", "Ada")set("user1", "city", "London")get("user1", "name")"Ada"get("user1", "email")Nonedelete("user1", "name")Truedelete("user1", "name")False
Level 1 looks easy, and it is. The test is in what comes after it: level 2 adds listing a record's fields in order, level 3 adds values that expire, and level 4 adds backups. Each one builds on the code you already wrote, and every earlier test keeps running.
The system itself changes from candidate to candidate. Candidates report a bank, a recipe manager, a task manager or an in-memory database, picked at random when the test starts (2 sources). The skills carry over from one system to the next, so this lesson practices them on three: your database, a task manager and a bank. The full problem at the end is the database.
Level 1 is the warm-up, and you write it over the next three screens, one method at a time. The steps after it teach what levels 2, 3 and 4 need. At the end you solve the whole problem, level by level, in an interview simulation with a 90-minute clock.
This lesson opens the coding builds, where the coding patterns come together. The database is a dict of dicts from the hash maps lesson, its scans sort the way the sorting steps below teach, and its expiry uses the half-open windows from the intervals lesson.