Code RoomOrdered index range query
MediumPrep Room Coding #204

Ordered index range query

CodingDatabases & SQLStorage & CDNMid–Senior~25 min

Model a simple ordered index (like a B-tree leaf level) over integer keys. You are given a list of operations. Each op is either ["insert", key] which adds key to the index (duplicates are ignored — the index is a set of keys), or ["range", lo, hi] which queries all keys k with lo <= k <= hi. Return a list with one sorted ascending list of keys for each "range" op, in the order the range ops appear. Keys are integers; there are at most 10^4 ops.

Implement
ordered_index(ops: list[list]) → list[list[int]]
Examples
in[[["insert",5],["insert",1],["insert",3],["range",2,5]]]out[[3,5]]
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.

0:00 of about 25 min
InputExpectedGot
[[["insert",5],["insert",1],["insert",3],["range",2,5]]][[3,5]]not run yetsample