Get Minimum Errors
Amazon's database 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.
Note: A subsequence of a string is obtained by omitting zero or more characters from the original string without changing their order.
Hint: It can be proved that (a + b) % c = ((a% c) + (b % c)) % c where a, b, and c are integers and % represents the modulo operation.
Complete the function getMinErrors in the editor.
getMinErrors has the following parameter(s):
String errorString: a string of characters '0', '1', and '!'int x: the number of errors generated for every occurrence of subsequence 01int y: the number of errors generated for every occurrence of subsequence 10
Returns
int: the minimum number of errors possible, modulo 109+7
♡ spike ໒꒱˚ deserves all the applause! 👏
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
1<= len (errorString)<=1050 <= x, y <= 105s consists only of characters '0', '1', and 'l'