Code Room
CodingMediumcod-g1054
Subject Storage indexLevel Mid–Senior~25 minCommon in Databases & SQL · Storage & CDN · Algorithms & data structures interviewsIndustries Software development, Technology

Question

An SSTable uses a sparse index: only the FIRST key of each data block is indexed. You are given `block_first_keys`, a list of the first integer key of each block in ascending block order (so the list is sorted ascending and all blocks are non-empty and key ranges don't overlap). For a list of point-lookup `queries` (integer keys), return for each query the 0-based index of the block that MUST be scanned to find it: the block whose first key is the largest first-key <= the query. If the query is smaller than the first block's first key, the key cannot exist, so return -1 for that query. Return the list of block indices, one per query in order. <= 10^5 blocks and queries.

Implement
sparse_index_lookup(block_first_keys: list[int], queries: list[int]) → list[int]
Examples
in[[10,20,30],[25,10,5]]out[1,0,-1]
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.