FastPrepBinary String Flip and Prefix Zero Counts

Binary String Flip and Prefix Zero Counts

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Maintain binaryString under requests:

  • flip inverts every bit and emits no output.
  • count:index appends 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

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] binaryPrefixZeroCounts(String binaryString, String[] requests) {
    // Write your code here.
}
binaryString"1111010"
requests["count:4","count:6","flip","count:4","flip","count:2"]
expected[1,2,4,0]
Checking account…