Question
Simulate an LSM-tree memtable with flush-on-threshold. Writes go to an in-memory memtable (a key→value map). When the memtable's distinct-key count reaches `threshold` immediately after a write, it is flushed: its sorted contents become a new immutable SSTable (level-0, newest first) and the memtable is cleared. A read for a key returns the memtable's value if present, otherwise scans SSTables from newest to oldest and returns the first hit, otherwise -1. Process operations ["put", key, value] and ["get", key]. Return [results, sstable_count] where results is the list of get results in order and sstable_count is the number of SSTables produced by flushes. Keys are strings, values are non-negative integers; threshold is a positive integer.
lsm_memtable(threshold: int, ops: list[list]) → list[2,[["put","a",1],["put","b",2],["get","a"],["put","a",9],["get","a"]]]out[[1,9],1]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.