Code Room
CodingMediumcod-g1043
Subject Storage lsmLevel Mid–Senior~30 minCommon in Storage & CDN · Algorithms & data structures interviewsIndustries Software development, Technology

Question

An LSM engine flushes a memtable and several on-disk SSTables, each given to you as a list of [key, value] pairs already sorted ascending by key. Runs are ordered oldest-first; the LAST run in the input is the newest. Merge them into a single sorted run where, for any key present in multiple runs, the value from the newest run wins. Return the merged list of [key, value] pairs sorted ascending by key. Keys are strings; total pairs across runs <= 10^5.

Implement
lsm_merge(runs: list[list[list]]) → list[list]
Examples
in[[[["a",1],["c",3]],[["b",2],["c",9]]]]out[["a",1],["b",2],["c",9]]
What a strong answer looks like

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.

Run or narrate your approach, then ask the coach.