Code RoomCovering index scan
HardPrep Room Coding #251

Covering index scan

CodingDatabases & SQLSenior–Staff~30 min

Simulate a covering index / index-only scan. You are given an index built over columns 'index_cols' (a list of column names) holding entries, each entry a dict containing exactly those columns plus 'row_id'. You are also given a query asking for columns 'needed_cols' and a range [lo, hi] on the FIRST index column (the leading key). If every needed column is present in the index (index covers the query), answer index-only: return entries whose leading-key value is in [lo,hi], projected to needed_cols, sorted ascending by the leading key (stable on ties). If not covered, return the string 'NEEDS_HEAP_FETCH'. Return either the list of projected dicts or that string.

Implement
covering_index_scan(index_cols: list[str], entries: list[dict], needed_cols: list[str], lo: int, hi: int) → object
Examples
in[["age","name"],[{"age":30,"name":"a","row_id":1},{"age":25,"name":"b","row_id":2},{"age":40,"name":"c","row_id":3}],["name"],26,40]out[{"name":"a"},{"name":"c"}]
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 30 min
InputExpectedGot
[["age","name"],[{"age":30,"name":"a","row_id":1},{"age":25,"name":"b","row_id":2},{"age":40,"name":"c","row_id":3}],["name"],26,40][{"name":"a"},{"name":"c"}]not run yetsample