FastPrepSingle-Digit Addition Equation Repairs

Single-Digit Addition Equation Repairs

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

a, b, and c are positive decimal strings containing no zero digits. Change exactly one digit in exactly one input to a different digit from 1 through 9.

Count substitutions after which a + b = c.

Function

countEquationRepairs(a: String, b: String, c: String) → int

Examples

Example 1

a = "7"b = "1"c = "7"return = 2

Changing b to 0 is forbidden; the two valid nonzero repairs satisfy the equation.

Example 2

a = "1"b = "1"c = "2"return = 0

The equation is already true, but exactly one different digit must be changed.

Constraints

  • 1 <= a.length,b.length,c.length <= 15

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int countEquationRepairs(String a, String b, String c) {
    // Write your code here.
}
a"7"
b"1"
c"7"
expected2
Checking account…