Problem · Prefix Sum
Binary String Requests
Learn this problemProblem statement
You are given a binary string and a sequence of requests:
flipchanges every0to1and every1to0.count:<index>counts the zeroes from position0through the given 0-based index, inclusive, in the string's current state.
Return the answers to the count requests in their processing order.
Function
databricksStringRequests(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]The first two prefixes contain 1 and 2 zeroes. After a flip, the prefix ending at index 4 contains 4 zeroes. The second flip restores the original string, whose prefix ending at index 2 contains none.
Constraints
🫎🫎