Simple Database Engine - Problem
Build a simple key-value database engine that supports basic CRUD operations (Create, Read, Update, Delete) with efficient indexing and data persistence.
Your database engine should implement:
- B-Tree indexing for fast key lookups
- Disk persistence to save/load data
- Basic operations:
put(key, value),get(key),delete(key),list()
The engine should handle a sequence of operations and return the final state as a list of key-value pairs sorted by key.
Input & Output
Example 1 — Basic CRUD Operations
$
Input:
operations = [["put","apple","red"],["put","banana","yellow"],["get","apple"],["delete","banana"],["put","cat","furry"]]
›
Output:
[["apple","red"],["cat","furry"]]
💡 Note:
Put apple→red, put banana→yellow, get apple returns red, delete banana, put cat→furry. Final state has apple and cat sorted by key.
Example 2 — Update Existing Key
$
Input:
operations = [["put","key1","value1"],["put","key1","updated"],["get","key1"]]
›
Output:
[["key1","updated"]]
💡 Note:
Put key1→value1, then update key1→updated. Get returns updated value. Final state contains the updated pair.
Example 3 — Empty Result
$
Input:
operations = [["put","temp","data"],["delete","temp"]]
›
Output:
[]
💡 Note:
Put temp→data then delete temp. Database becomes empty, so return empty array.
Constraints
- 1 ≤ operations.length ≤ 1000
- operations[i].length is either 2 (for get/delete) or 3 (for put)
- All keys and values are strings with length 1 ≤ length ≤ 100
- Keys contain only lowercase letters and numbers
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code