Code Room
CodingMediumcod-g1074
Subject Database indexLevel Mid–Senior~25 minCommon in Databases & SQL interviewsIndustries Software development, Technology

Question

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.

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.