FastPrepFastPrep
Problem Brief

Min Total Errors

FULLTIMEOA
See Amazon online assessment and hiring insights

See the Image Source section for the original statement :)

In a vast digital database, numbers were carefully stored as strings of binary characters—'0' and '1'. But something went wrong. In place of some digits, mysterious '!' marks appeared, casting doubt on what those digits should be. Should they be '0's or '1's? To make matters worse, whenever a '0' and '1' pair appeared together, they caused glitches—small errors that multiplied throughout the system. Some combinations triggered more glitches than others. The challenge now is to replace all the '!' marks in a way that minimizes the total glitches, while keeping the system stable and efficient.

1Example 1

Input
errorString = "101!1", x = 2, y = 3
Output
9
Explanation
For example, given the string errorString = "101!1" with two different error costs: If the '!' is replaced with '0', the string becomes "10101". In this case, the sequence '01' appears multiple times, and so does the sequence '10'. The total number of errors is calculated based on how often these sequences appear and their associated error costs, resulting in a higher error count. If the '!' is replaced with '1', the string changes to "10111". While '01' still occurs several times, '10' appears far less frequently, leading to a lower total error count. Therefore, the goal is to choose the replacement that results in fewer errors. In this case, the option with the lowest error count is the better choice.

Constraints

Limits and guarantees your solution can rely on.

Unknown for now
public int minTotalErrors(String errorString, int x, int y) {
  // write your code here
}
Input

errorString

"101!1"

x

2

y

3

Output

9

Sign in to submit your solution.