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! 👏
errorString = "101!1" x = 2 y = 3 return = 9
errorString = "01!0" x = 2 y = 2 return = 6
errorString = "!!!!!!!" x = 23 y = 27 return = 0
1<= len (errorString)<=1050 <= x, y <= 105s consists only of characters '0', '1', and 'l'- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
public int getMinErrors(String errorString, int x, int y) {
// write your code here
}