Problem Statement
Alice had two positive integers, a and b. She typed the expression "a+b" into her computer, but the '+' key malfunctioned. For example, instead of "128+9" the computer's screen now shows "1289".
Later, Bob saw the string on the screen. He knows that the '+' sign is missing but he does not know where it belongs. He now wonders what is the smallest possible result of Alice's original expression.
For example, if Bob sees the string "1289", Alice's expression is either "128+9" or "12+89" or "1+289". These expressions evaluate to 137, 101, and 290. The smallest of those three results is 101.
You are given a
Definition
- Class:
- ForgetfulAddition
- Method:
- minNumber
- Parameters:
- String
- Returns:
- int
- Method signature:
- int minNumber(String expression)
- (be sure your method is public)
Constraints
- expression will contain between 2 and 8 characters, inclusive.
- Each character of expression will be between '1' and '9'.
Examples
"22"
Returns: 4
The only possible expression Alice could have typed is "2+2". Thus, Bob knows this evaluates to 4.
"123"
Returns: 15
The expression Alice has typed could have been "1+23" or "12+3". Of these two, the second is smaller, thus Bob will get the answer 15.
"1289"
Returns: 101
This is the example from the problem statement.
"31415926"
Returns: 9067
"98765"
Returns: 863
"234855"
Returns: 1089
"8586"
Returns: 171
"21173236"
Returns: 5353
"1159"
Returns: 70
"3847"
Returns: 85
"29963625"
Returns: 6621
"938"
Returns: 47
"43"
Returns: 7
"67847587"
Returns: 14371
"21154"
Returns: 175
"79"
Returns: 16
"35194636"
Returns: 8155
"798716"
Returns: 1514
"9477"
Returns: 171
"999"
Returns: 108
"316795"
Returns: 1111
"18266324"
Returns: 8150
"5989"
Returns: 148
"1336"
Returns: 49
"9633"
Returns: 129
"6593799"
Returns: 4458
"273239"
Returns: 512
"326"
Returns: 29
"258584"
Returns: 842
"622289"
Returns: 911
"94526"
Returns: 620
"64783"
Returns: 730
"945768"
Returns: 1713
"96"
Returns: 15
"86446229"
Returns: 14873
"15974831"
Returns: 6428
"6964"
Returns: 133
"332594"
Returns: 926
"2595411"
Returns: 3006
"415"
Returns: 19
"1688"
Returns: 104
"8574"
Returns: 159
"225611"
Returns: 836
"38489"
Returns: 473
"2717351"
Returns: 3068
"532"
Returns: 37
"1135"
Returns: 46
"36313"
Returns: 349
"9145153"
Returns: 6067
"81"
Returns: 9
"1583131"
Returns: 1714
"7716"
Returns: 93
"1472"
Returns: 86
"2275"
Returns: 97
"862"
Returns: 70
"111"
Returns: 12
"9999"
Returns: 198
"23"
Returns: 5