Flash memory write erasures
Your task
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.
Examples
flash_erase_cycles(writes: list[int], word_bits: int) -> intExample 1
Input
flash_erase_cycles([12, 8, 15], 4)Output
1Example 2
Input
flash_erase_cycles([7, 7, 7], 4)Output
0Example 3
Input
flash_erase_cycles([0, 1], 4)Output
1