Secondary index queries

Write codeHard30 minSnowflake and Oracle style

Your task

Simulate a secondary index. You are given rows as [row_id, attr] pairs where attr is an integer (row_id is a unique int). Build a secondary index mapping attr to sorted list of row_ids. Then answer queries: each query is either ['eq', v] (all row_ids whose attr == v) or ['range', lo, hi] (all row_ids whose lo <= attr <= hi). For each query return the row_ids sorted ascending. Return a list of result lists, one per query.

Examples

secondary_index(rows: list[list[int]], queries: list[list]) -> list[list[int]]
Example 1
Inputsecondary_index([[10, 5], [11, 5], [12, 8], [13, 3]], [["eq", 5], ["range", 4, 8]])
Output[[10, 11], [10, 11, 12]]