total and a digit digit. Write total as a sum of positive integers that all end with the digit digit; the same number may be used more than once.
Return the smallest possible number of terms, or -1 if total cannot be written this way. An empty set of terms sums to 0.total=44, digit=7 → 2
For example 17 + 27 = 44: two terms, both ending in 7. One term is not enough, since 44 ends in 4.
total=15, digit=4 → -1
Any sum of numbers ending in 4 is even, and 15 is odd.
total=0, digit=3 → 0
An empty set of terms already sums to 0.
total=44, digit=7
2
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.