Problem Β· Prefix Sum
Binary String Requests
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 ΛΒ°
Examples
01 Β· Example 1
binaryString = "1111010" requests = ["count:4", "count:6", "flip", "count:4", "flip", "count:2"] return = [1, 2, 4, 0]
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
π«π«More Databricks problems
- Fastest SF CommutePHONE SCREEN Β· Seen May 2026
- Find First Anagram IndexPHONE SCREEN Β· Seen Apr 2026
- Minimize CommuteOA Β· Seen Apr 2026
- Difference Between Sums of PositionsSeen Sep 2024
- Longest Common Prefix of Number PairsSeen Sep 2024
- Subarray CountingSeen Sep 2024
- Write 'L' on MatrixSeen Sep 2024
- Bounding Diagonal WeightsSeen Aug 2024
public int[] databricksStringRequests(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]
sign in to submit