Problem
Minimize Binary Subsequence Cost
Learn this problemProblem statement
You are given a string binaryString consisting only of '0', '1', and '!', and two integers x and y.
Replace every '!' with either '0' or '1'. After replacement, every subsequence equal to "01" contributes cost x, and every subsequence equal to "10" contributes cost y.
Return the minimum possible total cost modulo 1_000_000_007.
Function
minimizeBinarySubsequenceCost(binaryString: String, x: int, y: int) → intExamples
Example 1
binaryString = "101!1"x = 2y = 3return = 9Replacing '!' with '0' gives cost 15. Replacing it with '1' gives cost 9, which is optimal.
Example 2
binaryString = "!!!!!"x = 2y = 3return = 0Replace all characters with the same bit, so there are no "01" or "10" subsequences.
Constraints
1 <= binaryString.length <= 10^50 <= x, y <= 10^5binaryStringcontains only'0','1', and'!'.