Code Room
CodingMediumcod-g1166
Subject Database indexLevel Mid–Senior~26 minCommon in Databases & SQL interviewsIndustries Software development

Question

A bitmap index represents each predicate as a list of row positions (0-based) where the predicate is true, given as a SORTED list of ints. Evaluate a boolean query: given bitmaps `a`, `b`, `c` and an operator string, return the sorted list of matching row ids. Supported operators: 'and' = a AND b, 'or' = a OR b, 'and_not' = a AND NOT b, 'and_or' = a AND (b OR c). Each input bitmap is sorted with no duplicates. The result must be sorted ascending with no duplicates.

Implement
bitmap_query(a: list[int], b: list[int], c: list[int], op: str) → list[int]
Examples
in[[0,1,2,3],[2,3,4],[],"and"]out[2,3]
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.