Code RoomOrdered index range scan
MediumPrep Room Coding #239

Ordered index range scan

CodingDatabases & SQLMid–Senior~25 min

Implement a simple ordered index used by a database to answer range scans. You are given a list of integer keys (possibly unsorted, possibly with duplicates) and a list of [lo, hi] range queries. Build a sorted index once, then for each query return the sorted list of keys k in the index with lo <= k <= hi, including duplicates. Keys fit in 64-bit ints; there may be up to 1e5 keys and queries. Return a list of result lists, one per query.

Implement
range_index(keys: list[int], queries: list[list[int]]) → list[list[int]]
Examples
in[[5,1,3,3,8],[[2,5],[3,3],[9,10]]]out[[3,3,5],[3,3],[]]
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
[[5,1,3,3,8],[[2,5],[3,3],[9,10]]][[3,3,5],[3,3],[]]not run yetsample