Statistics

Problem Statement for "MatchstickNumbers"

Problem Statement

Below is one specific way how to make digits out of matchsticks. Each '-' and each '|' represents one matchstick.

   +  +-+  +-+  + +  +-+
   |    |    |  | |  |
   +  +-+  +-+  +-+  +-+
   |  |      |    |    |
   +  +-+  +-+    +  +-+

 +-+  +-+  +-+  +-+  +-+
 |      |  | |  | |  | |
 +-+    +  +-+  +-+  + +
 | |    |  | |    |  | |
 +-+    +  +-+  +-+  +-+

We have taken all 10^9 nine-digit strings: from 000000000 to 999999999.

We have ordered them according to the number of matchsticks needed to build each of them (smaller to larger). Ties were broken using their numerical value (again, smaller to larger).

Given a 0-based index N into the sorted sequence, return a 9-digit String that is located at that index.

Definition

Class:
MatchstickNumbers
Method:
index
Parameters:
int
Returns:
String
Method signature:
String index(int N)
(be sure your method is public)

Constraints

  • N will be between 0 and 10^9 - 1, inclusive.

Examples

  1. 0

    Returns: "111111111"

    The only number that can be built using only 18 matchsticks is "111111111".

  2. 4

    Returns: "111117111"

    The next few numbers are the numbers that can be built using 19 matchsticks: at index 1 we have "111111117", at index 2 "111111171", at index 3 "111111711", and at index 4 we have "111117111".

  3. 10

    Returns: "111111114"

    At index 10 is the smallest 9-digit number that requires 20 matchsticks.

  4. 12

    Returns: "111111177"

    After "111111141" at index 11 we have "111111177" at index 12.

  5. 999999993

    Returns: "888889888"

    One of the numbers that require a very large number of matchsticks.

  6. 123456789

    Returns: "418035721"

  7. 1

    Returns: "111111117"

  8. 2

    Returns: "111111171"

  9. 3

    Returns: "111111711"

  10. 4

    Returns: "111117111"

  11. 5

    Returns: "111171111"

  12. 6

    Returns: "111711111"

  13. 7

    Returns: "117111111"

  14. 8

    Returns: "171111111"

  15. 9

    Returns: "711111111"

  16. 10

    Returns: "111111114"

  17. 11

    Returns: "111111141"

  18. 12

    Returns: "111111177"

  19. 13

    Returns: "111111411"

  20. 14

    Returns: "111111717"

  21. 15

    Returns: "111111771"

  22. 16

    Returns: "111114111"

  23. 17

    Returns: "111117117"

  24. 18

    Returns: "111117171"

  25. 19

    Returns: "111117711"

  26. 20

    Returns: "111141111"

  27. 377792061

    Returns: "357469281"

  28. 7

    Returns: "117111111"

  29. 999999992

    Returns: "888888988"

  30. 594466527

    Returns: "802170964"

  31. 27638

    Returns: "111211447"

  32. 999972361

    Returns: "980888308"

  33. 276411094

    Returns: "106529515"

  34. 116202

    Returns: "371441171"

  35. 999883797

    Returns: "988666080"

  36. 421352848

    Returns: "855247759"

  37. 567183

    Returns: "351171127"

  38. 999432816

    Returns: "896888284"

  39. 853713590

    Returns: "238248400"

  40. 8579

    Returns: "771111271"

  41. 999991420

    Returns: "888880895"

  42. 110011152

    Returns: "146772539"

  43. 999999998

    Returns: "988888888"

  44. 850666256

    Returns: "120999839"

  45. 33366

    Returns: "117114241"

  46. 999966633

    Returns: "898883008"

  47. 985054821

    Returns: "568588876"

  48. 109464962

    Returns: "141296795"

  49. 890535037

    Returns: "909494849"

  50. 609421745

    Returns: "963944354"

  51. 11961

    Returns: "113711714"

  52. 999988038

    Returns: "880898866"

  53. 255273378

    Returns: "750914246"

  54. 112601

    Returns: "271477117"

  55. 999887398

    Returns: "988893869"

  56. 999999999

    Returns: "888888888"


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: