Basic Bloom filter · Compiler

Basic Bloom filter

Maintain b bits initially set to 0 and numbered from 0 to b-1. For a key x, the two positions are x modulo b and floor(x / b) modulo b. ADD sets both bits to 1. CHECK reports whether both bits are 1, even if other keys set them. A check leaves the bits unchanged.

Input
The first line contains b q (1 <= b <= 100, 1 <= q <= 100). The next q lines each contain ADD x or CHECK x with an integer key from 0 to 10000. At least one command is CHECK.
Output
For each CHECK in order, print MAYBE if both positions contain 1 and NO otherwise, each on its own line.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…