Binary String Flip and Prefix Zero Counts
Problem statement
Maintain binaryString under requests:
flipinverts every bit and emits no output.count:indexappends the number of zeros from index 0 through the valid zero-based index, inclusive.
Return count answers in request order.
Function
binaryPrefixZeroCounts(binaryString: String, requests: String[]) → int[]Examples
Example 1
binaryString = "1111010"requests = ["count:4","count:6","flip","count:4","flip","count:2"]return = [1,2,4,0]Prefix counts use the current inversion state without emitting values for flips.
Example 2
binaryString = "0"requests = ["count:0","flip","count:0"]return = [1,0]The one bit changes from zero to one.
Constraints
1 <= binaryString.length,requests.length <= 100000