Set and Clear Bits
Problem statement
Start with the unsigned 32-bit word value. Process each row of operations in order. A row [0, bit] sets that bit to 1; a row [1, bit] clears it to 0. Bit 0 is the least significant bit and bit 31 is the most significant bit. Other bits do not change.
Return the unsigned numeric value after each operation. Setting a bit that is already 1 and clearing a bit that is already 0 leave the word unchanged. Use a wide integer for the input and results so that values above the signed 32-bit maximum stay positive.
Function
updateBits(value: long, operations: int[][]) → long[]Examples
Example 1
value = 5operations = [[0,1],[1,2],[0,1]]return = [7,3,3]The word starts as binary 101. Setting bit 1 gives 111, clearing bit 2 gives 011, and setting bit 1 again leaves 3.
Example 2
value = 0operations = [[0,31],[1,31]]return = [2147483648,0]Setting the highest bit produces the positive unsigned value 2147483648. Clearing it returns to 0.
Example 3
value = 8operations = []return = []There are no operations, so there are no reported intermediate values.
Constraints
0 <= value <= 4294967295.0 <= operations.length <= 10000.- Every operation has exactly two integers: its type is 0 or 1 and its bit index is from 0 through 31.