LSM-tree memtable

Write codeHard32 minMeta and Databricks style

Your task

Simulate an LSM-tree memtable with flush-on-threshold. Writes go to an in-memory memtable (a key to 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.

Examples

lsm_memtable(threshold: int, ops: list[list]) -> list
Example 1
Inputlsm_memtable(2, [["put", "a", 1], ["put", "b", 2], ["get", "a"], ["put", "a", 9], ["get", "a"]])
Output[[1, 9], 1]