Question
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.
covering_index_scan(index_cols: list[str], entries: list[dict], needed_cols: list[str], lo: int, hi: int) → object[["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"}]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.