Flash memory write erasures
A NOR flash page holds one word, and programming that word can only clear bits: a bit that already reads 0 can never be driven back to 1 without erasing the page, and an erase drives every bit of the word back to 1. The page starts erased. writes lists the values the firmware wants stored, in order, and word_bits gives the width of the word. Before each write the controller erases the page if and only if the wanted value cannot be reached from the stored value by clearing bits alone. Rewriting the value already stored costs nothing. Return how many erases the whole sequence costs. Every value is non-negative and fits inside word_bits bits.
flash_erase_cycles(writes: list[int], word_bits: int) → int[[12,8,15],4]out1[[7,7,7],4]out0[[0,1],4]out1State 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.
[[12,8,15],4]1not run yetsample[[7,7,7],4]0not run yetsample[[0,1],4]1not run yetsample