Statistics

Problem Statement for "ForgetfulAddition"

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 String expression that contains the expression on Alice's screen. Compute and return the smallest possible result after inserting the missing plus sign

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

  1. "22"

    Returns: 4

    The only possible expression Alice could have typed is "2+2". Thus, Bob knows this evaluates to 4.

  2. "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.

  3. "1289"

    Returns: 101

    This is the example from the problem statement.

  4. "31415926"

    Returns: 9067

  5. "98765"

    Returns: 863

  6. "234855"

    Returns: 1089

  7. "8586"

    Returns: 171

  8. "21173236"

    Returns: 5353

  9. "1159"

    Returns: 70

  10. "3847"

    Returns: 85

  11. "29963625"

    Returns: 6621

  12. "938"

    Returns: 47

  13. "43"

    Returns: 7

  14. "67847587"

    Returns: 14371

  15. "21154"

    Returns: 175

  16. "79"

    Returns: 16

  17. "35194636"

    Returns: 8155

  18. "798716"

    Returns: 1514

  19. "9477"

    Returns: 171

  20. "999"

    Returns: 108

  21. "316795"

    Returns: 1111

  22. "18266324"

    Returns: 8150

  23. "5989"

    Returns: 148

  24. "1336"

    Returns: 49

  25. "9633"

    Returns: 129

  26. "6593799"

    Returns: 4458

  27. "273239"

    Returns: 512

  28. "326"

    Returns: 29

  29. "258584"

    Returns: 842

  30. "622289"

    Returns: 911

  31. "94526"

    Returns: 620

  32. "64783"

    Returns: 730

  33. "945768"

    Returns: 1713

  34. "96"

    Returns: 15

  35. "86446229"

    Returns: 14873

  36. "15974831"

    Returns: 6428

  37. "6964"

    Returns: 133

  38. "332594"

    Returns: 926

  39. "2595411"

    Returns: 3006

  40. "415"

    Returns: 19

  41. "1688"

    Returns: 104

  42. "8574"

    Returns: 159

  43. "225611"

    Returns: 836

  44. "38489"

    Returns: 473

  45. "2717351"

    Returns: 3068

  46. "532"

    Returns: 37

  47. "1135"

    Returns: 46

  48. "36313"

    Returns: 349

  49. "9145153"

    Returns: 6067

  50. "81"

    Returns: 9

  51. "1583131"

    Returns: 1714

  52. "7716"

    Returns: 93

  53. "1472"

    Returns: 86

  54. "2275"

    Returns: 97

  55. "862"

    Returns: 70

  56. "111"

    Returns: 12

  57. "9999"

    Returns: 198

  58. "23"

    Returns: 5


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: