Problem Statement
Definition
- Class:
- QuickSums
- Method:
- minSums
- Parameters:
- String, int
- Returns:
- int
- Method signature:
- int minSums(String numbers, int sum)
- (be sure your method is public)
Constraints
- numbers will contain between 1 and 10 characters, inclusive.
- Each character in numbers will be a digit.
- sum will be between 0 and 100, inclusive.
Examples
"99999"
45
Returns: 4
In this case, the only way to achieve 45 is to add 9+9+9+9+9. This requires 4 additions.
"1110"
3
Returns: 3
Be careful with zeros. 1+1+1+0=3 and requires 3 additions.
"0123456789"
45
Returns: 8
"99999"
100
Returns: -1
"382834"
100
Returns: 2
There are 3 ways to get 100. They are 38+28+34, 3+8+2+83+4 and 3+82+8+3+4. The minimum required is 2.
"9230560001"
71
Returns: 4
"0000000000"
0
Returns: 0
"111"
3
Returns: 2
"1111111111"
10
Returns: 9
"1212121212"
15
Returns: 9
"1213121712"
21
Returns: 9
"0123456789"
81
Returns: 6
"8833614925"
100
Returns: -1
"0525222922"
93
Returns: -1
"3769558148"
99
Returns: -1
"1210102121"
100
Returns: -1
"0220120200"
63
Returns: 4
"0000000001"
1
Returns: 0
"1000000000"
1
Returns: 1
"1000000001"
2
Returns: 1
"1000000001"
11
Returns: 1
"1001098"
100
Returns: 2
"99999"
100
Returns: -1
"382834"
100
Returns: 2
"1110"
3
Returns: 3
"1"
1
Returns: 0