Problem Brief
Binary String Requests
INTERNOA
You are given a string binaryString consisting of '0's and '1's, as well as an array of strings requests containing requests of two types:
requests[i] = "count:<index>" - find the number of '0's in binaryString before and including the specified 0-based index.requests[i] = "flip" - flip all elements of binaryString, i.e. change every '0' to '1', and every '1' to '0'.
Return an array answers, where answers[i] contains the answer for the respective count request.
π‘βqΛββ Credit to ππ«§πΌ Charlotte ΛΒ°
1Example 1
Input
binaryString = "1111010", requests = ["count:4", "count:6", "flip", "count:4", "flip", "count:2"]
Output
[1, 2, 4, 0]
Explanation
Explnanation is an educated guess. If you find anythign wrong, pls feel free let me know! Manyyy thanks in advance!! π¦
For binaryString = "1111010" and requests = ["count:4", "count:6", "flip", "count:4", "flip", "count:2"], the output should be solution(binaryString, requests) = [1, 2, 4, 0].
- After the first request "count:4", the number of '0's before and including index 4 is 1.
- After the second request "count:6", the number of '0's before and including index 6 is 2.
- After the "flip" request, the binaryString becomes "0000101".
- After the next "count:4" request, the number of '0's before and including index 4 is 4.
- Another "flip" request changes the binaryString back to "1111010".
- Finally, after the "count:2" request, the number of '0's before and including index 2 is 0.
Constraints
Limits and guarantees your solution can rely on.
π«π«