Description
Solutions
Submission
Minimum Total Errors 🍉
🔥 FULLTIME

Databases doesn't support very large numbers, so numbers are stored as a string of binary characters, '0' and '1'. Accidentally, a ! was entered at some positions and it is unknown whether they should be '0' or '1'.

The string of incorrect data is made up of the characters '0', '1' and ! where '!' is the character that got entered incorrectly. '!' can be replaced with either '0' or '1'. Due to some internal faults, some errors are generated every time '0' and '1' occur together as '01' or '10' in any subsequence of the string. It is observed that the number of errors a subsequence '01' generates is x, while a subsequence '10' generates y errors.

Determine the minimum total errors generated? Since the answer can be very large, return it modulo 109+7.

Function Description

Complete the function minTotalErrors in the editor.

minTotalErrors has the following parameters:

  1. 1. String errorString: a string representing the binary data with errors
  2. 2. int x: the number of errors generated by the subsequence '01'
  3. 3. int y: the number of errors generated by the subsequence '10'

Returns

int: the minimum total errors generated, modulo (109 +7)

Example 1:

Input:  errorString = "101!1", x = 2, y = 3
Output: 9
Explanation:
For example, given string errorString = "101!1", x = 2, y = 3 - If the '!' at index 3 is replaced with '0', the string is "10101". The number of times the subsequence 01 occurs is 3 at indices (1, 2), (1, 4), and (3,4). The number of times the subsequence 10 occurs is also 3 at indices (0, 1), (0, 3) and (2, 3). The number of errors is 3 * x+3 * y=6 + 9 = 15. - If the '!' is replaced with '1', the string is "10111". The subsequence 01 occurs 3 times and 10 occurs 1 time. The number of errors is 3 * x + y = 9. The minimum number of errors is min(9, 15) modulo (109 +7) = 9.
Constraints:
    Unknown for now
Thumbnail 0
Testcase

Result
Case 1

input:

output: