In-Memory SQL Engine
Also known as: In-Memory SQL Engine (Custom)
In-Memory SQL Engine You're building a tiny in-memory SQL system (no real database). All values are strings, and each table has a fixed column order. Implement class SQL with these methods: - createTable(tableName, columns): Create OR REPLACE a table (drop existing rows). - insertRow(tableName, values): Insert a row where values[i] corresponds to columns[i]. - deleteRows(tableName, whereColumn, whereValue): Delete ALL rows matching the filter. - selectRows(tableName, columns, whereColumn, whereValue): Return matching rows, projecting only the requested columns, in insertion order. run_sql_script below executes a list of commands against your SQL instance.
You're implementing CREATE, INSERT, SELECT, and DELETE from scratch—no shortcuts. Interviewers love it because it exposes whether you can follow a spec precisely without drifting. The trap is getting lost in state management halfway through. Keep your table representation explicit and the rest follows.
Examples
You write
SQL: createTable(tableName: str, columns: List[str]), insertRow(tableName: str, row: List[str]), deleteRows(tableName: str, whereColumn: str, whereValue: str)
Example 1
- Input
- Employees: find name + salary where employee_id = 2
- returns
- [["Bob","90000"]]
Example 2
- Input
- Projects: filter by project_name = Beta
- returns
- [["Beta"]]
The pattern behind it
Design
I reach for it when
- The statement describes a class with methods, not one function.
- Each method needs to be fast, and the structure decides how fast.
Say this before you type. Say each method, the cost you want from it, and the structure that earns that cost.
All 27 Design problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.
Each locked part opens in the editor once the part before it passes.