Index page fetches

Write codeEasy16 minOracle and Snowflake style

Your task

A reporting engine answers each query through an unclustered secondary index. The index hands back one pointer per matching row, in index key order, and a pointer names the heap page that row lives on. The engine holds exactly one heap page at a time, so walking the pointers in index order fetches a page whenever the next pointer names a page other than the one it is already holding, and a page left behind can be fetched again later. A bitmap scan instead gathers all the pointers first, sorts them, and fetches each distinct page exactly once. Each entry of queries is one query's pointer list, in index order. Return a list holding, for each query in input order, how many page fetches the bitmap scan saves. A query that matched nothing saves 0. Return an empty list when no queries are given.

Examples

bitmap_scan_savings(queries: list[list[int]]) -> list[int]
Example 1
Inputbitmap_scan_savings([[4, 4, 7, 7, 4], [9], [2, 5, 2, 5]])
Output[1, 0, 2]
Example 2
Inputbitmap_scan_savings([[11, 11, 11, 12, 12, 13]])
Output[0]
Example 3
Inputbitmap_scan_savings([[3, 8, 3, 8, 3, 8, 3]])
Output[5]