Statistics

Problem Statement for "MatchNumbersHard"

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 String[] matches and a String 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 a String[] such that the first element is the number of digits of x (where x is the largest number that can be created), the second element contains the first 50 digits of x, and the third element contains the last 50 digits of x. If x has fewer than 50 digits, the second and third elements should each be all of x. No extra leading zeros should be added to any returned value. If n is too small to create any number, return a single zero as the number of digits and empty strings ("") as the second and third elements.

Definition

Class:
MatchNumbersHard
Method:
maxNumber
Parameters:
String[], String
Returns:
String[]
Method signature:
String[] maxNumber(String[] matches, String 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 an integer between 1 and 10 ^ 18 (fits in a long), inclusive, with no leading zeros.
  • n will be an integer between 0 and 10 ^ 18 (fits in a long), inclusive, with no extra leading zeros.

Examples

  1. {"6","7","8"}

    "21"

    Returns: {"3", "210", "210" }

    Example from the problem statement.

  2. {"1","7","8"}

    "21"

    Returns: {"15", "100000000000000", "100000000000000" }

  3. {"1","1","1","1","1","1","1","1","1","1"}

    "923372036854775807"

    Returns: {"923372036854775807", "99999999999999999999999999999999999999999999999999", "99999999999999999999999999999999999999999999999999" }

    A lot of nines.

  4. {"1","923372036854775807"}

    "923372036854775807"

    Returns: {"1", "1", "1" }

  5. {"1","923372036854775806"}

    "923372036854775807"

    Returns: {"2", "10", "10" }

  6. {"1","5","10"}

    "10"

    Returns: {"6", "100000", "100000" }

  7. {"1","923372036854775807"}

    "923372036854775806"

    Returns: {"1", "0", "0" }

    Zero is the only digit that can be created. Note that no extra leading zeros should be added to any returned value.

  8. {"923372036854775807","50","60"}

    "2760"

    Returns: {"55", "21111111111111111111111111111111111111111111111111", "11111111111111111111111111111111111111111111111111" }

  9. {"923372036854775807","50","60"}

    "2010"

    Returns: {"40", "2111111111111111111111111111111111111111", "2111111111111111111111111111111111111111" }

  10. {"1", "10"}

    "1000000"

    Returns: {"999991", "10000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

    There are 999990 zeros in the created number, so its last 50 digits are all zeros.

  11. {"1000000000000000", "1000000000000010", "1000000000000100", "1000000000001000", "1000000000010000", "1000000000100000", "1000000001000000", "1000000010000000", "1000000100000000", "1000001000000000" }

    "200000003333333330"

    Returns: {"200", "99988877766655544433322211100000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  12. {"1000000000000000", "1000000000000010", "1000000000000100", "1000000000001000", "1000000000010000", "1000000000100000", "1000000001000000", "1000000010000000", "1000000100000000", "1000001000000000" }

    "200000170333333330"

    Returns: {"200", "99999999999999999999999999999999999999999999999999", "99999999999999999999888777666555444333222111000000" }

  13. {"923372036854775807"}

    "923372036854775807"

    Returns: {"1", "0", "0" }

  14. {"923372036854775807", "923372036854775807", "923372036854775807"}

    "923372036854775807"

    Returns: {"1", "2", "2" }

  15. {"13252", "10185", "2935", "7098", "3119", "3190", "4338"}

    "8451"

    Returns: {"2", "65", "65" }

  16. {"13252", "10185", "2817", "7098", "3119", "3190", "4338"}

    "8451"

    Returns: {"3", "222", "222" }

  17. {"99119939999969995","99119939999969998","99119939999969999"}

    "99119939999969997"

    Returns: {"1", "0", "0" }

  18. {"1","835810052671059340","835810052167105935","658100521671059340","835810055648722340"}

    "958100521671059340"

    Returns: {"300000000000000001", "30000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  19. {"1000000000000000000","1000000000000000000","1000000000000000000","1","1000000000000000000","1000000000000000000","1000000000000000000","1","1000000000000000000","1000000000000000000"}

    "999999999999999999"

    Returns: {"999999999999999999", "77777777777777777777777777777777777777777777777777", "77777777777777777777777777777777777777777777777777" }

  20. {"1","1","1","1","1","1","1","1","1","1"}

    "1000000000000000000"

    Returns: {"1000000000000000000", "99999999999999999999999999999999999999999999999999", "99999999999999999999999999999999999999999999999999" }

  21. {"1","1","1","1","1","1","1","1"}

    "1000000000000000000"

    Returns: {"1000000000000000000", "77777777777777777777777777777777777777777777777777", "77777777777777777777777777777777777777777777777777" }

  22. {"1"}

    "1000000000000000000"

    Returns: {"1", "0", "0" }

  23. {"1","2","4","8","16","32","64","128","256","512"}

    "16383"

    Returns: {"16382", "10000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  24. {"1000000000000000000","999315786","1000000000000000000","999315787","1000000000000000000","1000000000000000000","1000000000000000000","1000000000000000000","1000000000000000000"}

    "998632045145376725"

    Returns: {"999315790", "33333333333333333333333333333333333333333333333333", "33333333333333333333333333333333333333333333311111" }

  25. {"934759010915109991","1000","1002","1004","1008","1016","1032","1064","1128","1256"}

    "9511"

    Returns: {"9", "987654321", "987654321" }

  26. {"1","737470023400002341","2","5","3","4","2","3"}

    "1000000000000000000"

    Returns: {"999999999999999999", "60000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  27. {"1","737470023400002341","2","5","3","4","2","3"}

    "999932030020000050"

    Returns: {"999932030020000049", "60000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  28. {"1","99119939999969998","99119939999969999"}

    "99119939999969997"

    Returns: {"1", "0", "0" }

  29. {"33","330000000000"}

    "330000000000"

    Returns: {"1", "1", "1" }

  30. {"33","3301"}

    "3307"

    Returns: {"1", "1", "1" }

  31. {"842850236509000000","842850236509000001","842850236509000002"}

    "842850236509002315"

    Returns: {"1", "2", "2" }

  32. {"346","128474985098436704","128474985098436702","321425"}

    "128474985098436704"

    Returns: {"371314985832704", "30000000000000000000000000000000000000000000000000", "00000000000000000000000000000000000000000000000000" }

  33. {"346","128474985098436704","128474985098436300"}

    "128474985098436704"

    Returns: {"2", "20", "20" }

  34. {"346","128474985098436704","347"}

    "128474985098436704"

    Returns: {"371314985833632", "22222222222222222222222222222222000000000000000000", "00000000000000000000000000000000000000000000000000" }

  35. {"1000000000000000000","713260892687687","713260892826940","713260892966196","713260894637276","713260972620995","713364805987902","714403938990070","740694003944857","1069891339030898"}

    "999991771548135907"

    Returns: {"1401", "98888888888887777777777777777777777766666666665555", "44444444444444444444444444444444443333332111111111" }

  36. {"1000000000000000000","709419836063046","709419836201551","709419836340056","709419838002126","709419915565897","709523189768766","710556726825966","736705214373127","1064129754094098"}

    "994606610160389548"

    Returns: {"1401", "98888888888887777777777777777777777766666666665555", "44444444444444444444444444444444443333332111111111" }

  37. {"1000000000000000000","695180444914857","695180445186305","695180445457756","695180448715186","695180600729015","695383003319552","697408587366504","748655863754388","1390360889828752"}

    "974642983770628551"

    Returns: {"1401", "88888888888877777777777777777777777666666666655555", "44444444444444444444444444444444433333321111111111" }

  38. {"1000000000000000000","19293382955104","19293382955134","19293382955169","19293382955619","19293382959746","19293383034115","19297436186810","19350128198986","20428287832746"}

    "991718470658220612"

    Returns: {"51401", "99999999999999998888888888888888888777777777777766", "55555444444443333333211111111111111111111111111111" }

  39. {"1000000000000000000","59398403","59398404","59398404","59398404","59398404","59398404","59461053","61653783","68419920"}

    "957558588169314466"

    Returns: {"16120948372", "99888777777777777777777777777777777777776666666666", "11111111111111111111111111111111111111111111111111" }

  40. {"1000000000000000000","59398403","59398404","59398404","59398404","59398404","59398404","59461053","61653783","68419920"}

    "957558588169314466"

    Returns: {"16120948372", "99888777777777777777777777777777777777776666666666", "11111111111111111111111111111111111111111111111111" }

  41. {"1000000000000000000","149281225","149281226","149281226","149281226","149281226","149281226","149421313","154324363","169453778"}

    "746389517822798856"

    Returns: {"4999888752", "99888777777777777777777777777777777777776666666666", "11111111111111111111111111111111111111111111111111" }

  42. {"1000000000000000000","621991264853","621991264854","621991264854","621991264854","621991264854","621991266293","623431057594","673823803496","829321419423"}

    "746389517822798856"

    Returns: {"1199999", "99888777777777777777777777777777777777776666666666", "11111111111111111111111111111111111111111111111111" }

  43. {"1000000000000000000","95690963823436","95690963823481","95690963823659","95690963826564","95690963864730","95690995211684","95912470684134","103665210808561","127587951763934"}

    "746389517822798856"

    Returns: {"7799", "99888777777777777777777777777777777777776666666666", "55555555555555555555555555555555555555555555555555" }

  44. {"1000000000000000000","127933563369162","127933563369243","127933563369574","127933563374923","127933563444095","127933605333525","128229705876955","138594693649686","170578084491258"}

    "997881794279460724"

    Returns: {"7799", "99888777777777777777777777777777777777776666666666", "11111111111111111111111111111111111111111111111111" }

  45. {"1000000000000000000","127933563369162","127933563369230","127933563369504","127933563373955","127933563431793","127933605333525","128229705876955","138594693649686","170578084491258"}

    "997881794279460724"

    Returns: {"7799", "99888777777777777777777777777777777777776666666666", "55555555555555554444444444443333333333333222211111" }

  46. {"1000000000000000000","127933563369162","127933563369172","127933563369267","127933563370838","127933563388092","127933576134037","128023594026000","130544452417454","146209786707203"}

    "997881794279460724"

    Returns: {"7799", "99999988888877777777777777777777777777776666666666", "55555555555555554444444444333333333333333222222222" }

  47. {"1000000000000000000","1635871793900756","1635871887616475","1635875355098497","1637581168816012","1000000000000000000","1000000000000000000","1692281166104216","1000000000000000000","1000000000000000000"}

    "997881794279460724"

    Returns: {"609", "77777777777777777777777777774444444444444444444444", "22222222222222222111111111111111111111111111111111" }

  48. {"1247352242849326","1000000000000000000","1000000000000000000","1247397192479699","1000000000000000000","1000000000000000000","1281064465629036","1000000000000000000","1000000000000000000","1000000000000000000"}

    "997881794279460724"

    Returns: {"799", "66666666666666666666666666666666666633333333333333", "33333333333333333333333333333333333300000000000000" }

  49. {"1052529643181078","1000000000000000000","1000000000000000000","1052530822485999","1000000000000000000","1000000000000000000","1052547332754913","1067565780940797","1000000000000000000","1000000000000000000"}

    "999903161022023351"

    Returns: {"949", "77777777777777777777777777777777777777777777777777", "66666666666666666663333333333333300000000000000000" }

  50. {"1052529643181078","1000000000000000000","1000000000000000000","1052530350764031","1000000000000000000","1000000000000000000","1052547332754913","1067565780940797","1000000000000000000","1000000000000000000"}

    "999903161022023351"

    Returns: {"949", "77777777777777777777777777777777777777777777777777", "66666666666666666663333333333333333333333330000000" }

  51. {"1052529643181078","1000000000000000000","1000000000000000000","1052530148597473","1000000000000000000","1000000000000000000","1052547332754913","1067565780940797","1000000000000000000","1000000000000000000"}

    "999903161022023351"

    Returns: {"949", "77777777777777777777777777777777777777777777777777", "66666666666666666663333333333333333333333333333333" }

  52. {"10"}

    "1"

    Returns: {"0", "", "" }

  53. {"1"}

    "0"

    Returns: {"0", "", "" }

  54. {"1","1"}

    "0"

    Returns: {"0", "", "" }

  55. {"1000", "1001" }

    "400090"

    Returns: {"400", "11111111111111111111111111111111111111111111111111", "00000000000000000000000000000000000000000000000000" }

  56. {"10000", "10001" }

    "980049"

    Returns: {"98", "11111111111111111111111111111111111111111111111110", "10000000000000000000000000000000000000000000000000" }

  57. {"123412341234" }

    "234"

    Returns: {"0", "", "" }

  58. {"19" }

    "3957127598359284"

    Returns: {"1", "0", "0" }

  59. {"10", "10" }

    "9"

    Returns: {"0", "", "" }

  60. {"1" }

    "10000"

    Returns: {"1", "0", "0" }

  61. {"100" }

    "1"

    Returns: {"0", "", "" }

  62. {"100000000000000", "1000000000", "1000000001" }

    "999999999999999999"

    Returns: {"999999999", "22222222222222222222222222222222222222222222222222", "22222222222222222222222222222222222222222222222222" }

  63. {"10", "11", "11" }

    "21"

    Returns: {"2", "20", "20" }

  64. {"999", "1000" }

    "399800"

    Returns: {"400", "11111111111111111111111111111111111111111111111111", "00000000000000000000000000000000000000000000000000" }

  65. {"10" }

    "1"

    Returns: {"0", "", "" }

  66. {"1", "923372036854775807" }

    "923372036854775806"

    Returns: {"1", "0", "0" }

  67. {"1", "1000" }

    "100"

    Returns: {"1", "0", "0" }

  68. {"10000000", "20000000", "20000001", "20000002", "20000003", "20000004", "20000005", "20000006", "20000007", "10000001" }

    "10000000099999999"

    Returns: {"1000000009", "99999999999999999999999999999999999999999999999999", "00000000000000000000000000000000000000000000000000" }


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: