Code Room
CodingMediumcod-g963
Subject Storage systemsLevel Mid–Senior~28 minCommon in Storage & CDN · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Implement a Bloom filter with a bit array of size `m` and `k` hash functions. For a string s and hash index j (0-indexed), the j-th hash is h_j(s) = (sum((ord(c) * (j + 1) * (idx + 1)) for idx, c in enumerate(s)) * 2654435761 + j * 0x9E3779B1) % m, which sets/checks bit h_j(s). Given m, k, a list of strings to insert, and a list of query strings, return for each query 0 if the filter definitely does NOT contain it (at least one of its k bits is unset) or 1 if it might be present (all k bits set). Inserts are applied first, then queries. m is between 1 and 100000; k is between 1 and 16.

Implement
bloom_filter(m: int, k: int, inserts: list[str], queries: list[str]) → list[int]
Examples
in[1000,3,["apple","banana"],["apple","cherry"]]out[1,0]
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.