Statistics

Problem Statement for "MatchNumbersEasy"

Problem Statement

Each digit can be represented using a certain number of matches. Your goal is to create the largest possible number using the matches that you have. For example, if you need 6 matches for zero, 7 matches for one, and 8 matches for two, and you have 21 matches, the largest number you can create is 210 (8 + 7 + 6 = 21 matches).

You are given a int[] matches and an int n. The ith element (zero-indexed) of matches is the number of matches needed to represent the digit i. n is the number of matches you have. Return the largest possible number you can create without extra leading zeros.

Definition

Class:
MatchNumbersEasy
Method:
maxNumber
Parameters:
int[], int
Returns:
String
Method signature:
String maxNumber(int[] matches, int n)
(be sure your method is public)

Notes

  • It is not necessary to use all given matches. Some matches may be left unused.

Constraints

  • matches will contain between 1 and 10 elements, inclusive.
  • Each element of matches will be between 1 and 50, inclusive.
  • n will be between 1 and 50, inclusive.
  • n matches will be enough to construct at least 1 digit.

Examples

  1. {6,7,8}

    21

    Returns: "210"

    Example from the problem statement.

  2. {5,23,24}

    30

    Returns: "20"

    24 matches for two and 5 matches for zero. 1 match is left unused.

  3. {1,5,3,2}

    1

    Returns: "0"

    This is the only number that can be created.

  4. {1,1,1,1,1,1,1,1,1,1}

    50

    Returns: "99999999999999999999999999999999999999999999999999"

  5. {2,20,30}

    19

    Returns: "0"

  6. {1,5,10}

    9

    Returns: "10000"

  7. {1,5,10}

    10

    Returns: "100000"

  8. {43,46,45,47,48,50}

    44

    Returns: "0"

  9. {1,46,43,47,36,50,49}

    42

    Returns: "4000000"

  10. {40,1,40,1,40,1,40,40,1,40}

    39

    Returns: "888888888888888888888888888888888888888"

  11. {50,50,50,1,50,50,1,50,50,1}

    50

    Returns: "99999999999999999999999999999999999999999999999999"

  12. {10,12,14}

    49

    Returns: "2200"

  13. {50,49,10,47,11,45,13,15}

    49

    Returns: "7642"

  14. {6,8,9,10,10,11,12,14,15,15}

    40

    Returns: "400000"

  15. {6,7,7,9,11,11,11,13,15,15}

    41

    Returns: "600000"

  16. {5,5,7,8,10,10,10,11,12,13}

    41

    Returns: "11111111"

  17. {7,9,11,11,12,12,13,14,15,15}

    42

    Returns: "70000"

  18. {5,6,6,8,9,9,9,11,11,11}

    50

    Returns: "620000000"

  19. {8,10,11,11,13,15,17,18,19,20}

    40

    Returns: "5000"

  20. {7,7,7,7,9,11,11,13,14,16}

    46

    Returns: "633333"

  21. {8,9,11,12,14,14,15,15,15,17}

    50

    Returns: "110000"

  22. {5,6,6,7,7,9,9,11,11,12}

    48

    Returns: "420000000"

  23. {6,7,9,11,11,12,12,14,15,15}

    50

    Returns: "11000000"

  24. {43,46,45,47,48,50}

    44

    Returns: "0"

  25. {1,46,43,47,36,50,49}

    42

    Returns: "4000000"

  26. {40,1,40,1,40,1,40,40,1,40}

    39

    Returns: "888888888888888888888888888888888888888"

  27. {50,50,50,1,50,50,1,50,50,1}

    50

    Returns: "99999999999999999999999999999999999999999999999999"

  28. {10,12,14}

    49

    Returns: "2200"

  29. {50,49,10,47,11,45,13,15}

    49

    Returns: "7642"

  30. {2,4,5,12,9,7,8,16,17,23}

    47

    Returns: "2000000000000000000000"

  31. {50,7,50,8,8,50,50,10,50,50}

    48

    Returns: "771111"

  32. {50,5,50,6,6,50,50,7,50,50}

    48

    Returns: "741111111"

  33. {50,5,50,6,6,50,50,7,50,50}

    48

    Returns: "741111111"

  34. {50,50,7,8,10,50,50,11,50,50}

    48

    Returns: "733222"

  35. {50,50,9,10,11,50,50,12,50,50}

    49

    Returns: "73222"

  36. {50,50,9,14,14,50,50,14,50,50}

    49

    Returns: "22222"

  37. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    50

    Returns: "99999999999999999999999999999999999999999999999999"

  38. {2, 3, 4, 5, 6, 7, 8, 9, 4, 4 }

    11

    Returns: "10000"

  39. {6, 7, 8 }

    21

    Returns: "210"

  40. {1, 2, 2, 2, 2, 2, 2, 2, 2, 2 }

    50

    Returns: "9000000000000000000000000000000000000000000000000"

  41. {3, 2, 5 }

    21

    Returns: "1111111111"

  42. {1, 9, 8 }

    4

    Returns: "0"

  43. {8, 7, 6 }

    21

    Returns: "222"

  44. {5, 2, 4 }

    4

    Returns: "11"

  45. {2, 3, 4, 5, 6, 7, 8, 9 }

    50

    Returns: "200000000000000000000000"

  46. {9, 7, 8 }

    7

    Returns: "1"

  47. {1, 1, 4, 4 }

    6

    Returns: "111111"

  48. {1, 2, 3 }

    4

    Returns: "100"

  49. {2, 6 }

    4

    Returns: "0"

  50. {1, 7, 3, 8, 9, 6, 2, 4, 9, 5 }

    50

    Returns: "6000000000000000000000000000000000000000000000000"

  51. {1, 2, 3, 4, 3, 23, 32 }

    50

    Returns: "1000000000000000000000000000000000000000000000000"

  52. {1, 2, 1, 3, 1, 4, 2, 6, 1, 3 }

    50

    Returns: "88888888888888888888888888888888888888888888888888"

  53. {1, 2, 1, 1, 1, 1, 1, 1, 2, 1 }

    48

    Returns: "999999999999999999999999999999999999999999999999"

  54. {1, 9, 10 }

    19

    Returns: "10000000000"

  55. {2, 9, 6, 3, 7, 4 }

    9

    Returns: "3000"

  56. {1, 1, 1, 1, 2 }

    45

    Returns: "333333333333333333333333333333333333333333333"

  57. {3, 1, 3, 2 }

    50

    Returns: "11111111111111111111111111111111111111111111111111"

  58. {3, 1, 3, 2, 4, 5 }

    50

    Returns: "11111111111111111111111111111111111111111111111111"

  59. {2, 3, 5 }

    5

    Returns: "10"

  60. {6, 14, 22, 1, 2, 24, 21 }

    47

    Returns: "33333333333333333333333333333333333333333333333"

  61. {1, 1, 47 }

    49

    Returns: "1111111111111111111111111111111111111111111111111"

  62. {5, 23, 24 }

    30

    Returns: "20"

  63. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    50

    Returns: "1000000000000000000000000000000000000000000000000"

  64. {1 }

    1

    Returns: "0"

  65. {2, 3, 12 }

    24

    Returns: "11000000000"

  66. {1, 1, 1, 25 }

    25

    Returns: "2222222222222222222222222"

  67. {50, 5, 10 }

    10

    Returns: "11"

  68. {3, 20 }

    40

    Returns: "1000000"

  69. {40 }

    45

    Returns: "0"

  70. {5, 3, 1 }

    5

    Returns: "22222"

  71. {7, 1, 6 }

    7

    Returns: "1111111"

  72. {5, 11, 12 }

    10

    Returns: "0"

  73. {2, 2, 2, 2, 2, 2, 2, 2, 2 }

    49

    Returns: "888888888888888888888888"

  74. {2, 5, 23, 24 }

    30

    Returns: "1000000000000"

  75. {1, 1, 3, 2 }

    1

    Returns: "1"

  76. {1, 9, 49 }

    49

    Returns: "10000000000000000000000000000000000000000"


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: