Statistics

Problem Statement for "SoldierLabeling"

Problem Statement

Tom is a little boy who likes to collect toys. On his birthday, his mom bought him a box of toy soldiers as a gift. There are n soldiers in the box, labeled 1 to n on their uniforms. The numbers are written with no leading zeroes. Tom starts counting the soldiers, but he soon finds that it's difficult to count them all. He decides to count only the soldiers with labels that have length between lowerBound and upperBound, inclusive. Return the number of soldiers that Tom will count.

Definition

Class:
SoldierLabeling
Method:
count
Parameters:
int, int, int
Returns:
int
Method signature:
int count(int n, int lowerBound, int upperBound)
(be sure your method is public)

Constraints

  • n will be between 1 and 10,000,000, inclusive.
  • lowerBound will be between 1 and 8, inclusive.
  • upperBound will be between lowerBound and 8, inclusive.

Examples

  1. 100

    2

    2

    Returns: 90

    Here there are 100 soldiers and they're labeled 1 to 100. The labels between 10 and 99, inclusive, are of length 2.

  2. 31

    2

    3

    Returns: 22

    Here there are 31 soldiers and we're looking for labels of length between 2 and 3, inclusive. There are no labels of length 3. Labels between 10 and 31, inclusive, are of length 2.

  3. 1

    2

    8

    Returns: 0

    Here there is only one soldier and it is labeled 1. We're looking for labels of length between 2 and 8, inclusive, and there are none.

  4. 10000000

    8

    8

    Returns: 1

    Label 10000000 is the only one here of length 8.

  5. 2718317

    3

    7

    Returns: 2718218

  6. 10000000

    1

    8

    Returns: 10000000

  7. 9999999

    7

    8

    Returns: 9000000

  8. 42

    2

    2

    Returns: 33

  9. 4

    1

    2

    Returns: 4

  10. 4560

    3

    5

    Returns: 4461

  11. 596427

    1

    7

    Returns: 596427

  12. 2

    1

    2

    Returns: 2

  13. 35631

    2

    6

    Returns: 35622

  14. 8319

    2

    4

    Returns: 8310

  15. 7

    1

    2

    Returns: 7

  16. 49

    2

    3

    Returns: 40

  17. 44063

    4

    6

    Returns: 43064

  18. 8

    1

    2

    Returns: 8

  19. 59

    3

    3

    Returns: 0

  20. 4351423

    4

    7

    Returns: 4350424

  21. 75291

    5

    6

    Returns: 65292

  22. 78363

    2

    5

    Returns: 78354

  23. 950193

    4

    4

    Returns: 9000

  24. 790027

    2

    3

    Returns: 990

  25. 60078

    1

    5

    Returns: 60078

  26. 31

    2

    2

    Returns: 22

  27. 2349

    4

    4

    Returns: 1350

  28. 949

    1

    4

    Returns: 949

  29. 538

    3

    4

    Returns: 439

  30. 2763

    2

    5

    Returns: 2754

  31. 3562947

    5

    8

    Returns: 3552948

  32. 6028964

    6

    7

    Returns: 5928965

  33. 28

    1

    3

    Returns: 28

  34. 550516

    1

    5

    Returns: 99999

  35. 9780322

    5

    7

    Returns: 9770323

  36. 45516

    1

    2

    Returns: 99

  37. 5645825

    2

    4

    Returns: 9990

  38. 52

    3

    3

    Returns: 0

  39. 9

    1

    1

    Returns: 9

  40. 3171926

    1

    5

    Returns: 99999

  41. 2771431

    1

    1

    Returns: 9

  42. 7

    1

    1

    Returns: 7

  43. 10

    3

    3

    Returns: 0

  44. 8242164

    5

    8

    Returns: 8232165

  45. 5323

    2

    4

    Returns: 5314

  46. 2554198

    1

    8

    Returns: 2554198

  47. 79379

    1

    6

    Returns: 79379

  48. 427

    3

    3

    Returns: 328

  49. 7

    1

    1

    Returns: 7

  50. 915

    1

    4

    Returns: 915

  51. 421

    3

    4

    Returns: 322

  52. 3

    2

    2

    Returns: 0

  53. 9496898

    4

    6

    Returns: 999000

  54. 8

    2

    2

    Returns: 0

  55. 6430534

    1

    6

    Returns: 999999

  56. 234

    1

    1

    Returns: 9

  57. 828718

    4

    7

    Returns: 827719

  58. 10000000

    2

    8

    Returns: 9999991

  59. 10000000

    1

    1

    Returns: 9

  60. 1

    1

    1

    Returns: 1

  61. 9999999

    1

    7

    Returns: 9999999

  62. 10

    1

    1

    Returns: 9

  63. 10000

    2

    2

    Returns: 90

  64. 990

    1

    4

    Returns: 990

  65. 999999

    3

    4

    Returns: 9900

  66. 100000

    1

    1

    Returns: 9

  67. 1114

    1

    1

    Returns: 9

  68. 10000000

    5

    5

    Returns: 90000

  69. 9976876

    3

    7

    Returns: 9976777

  70. 152356

    2

    3

    Returns: 990

  71. 1

    2

    3

    Returns: 0

  72. 1000

    2

    2

    Returns: 90

  73. 999

    1

    1

    Returns: 9

  74. 2718317

    1

    1

    Returns: 9

  75. 95

    2

    2

    Returns: 86

  76. 99

    3

    7

    Returns: 0

  77. 15

    1

    2

    Returns: 15

  78. 10000000

    4

    8

    Returns: 9999001

  79. 10000000

    1

    3

    Returns: 999

  80. 8

    1

    1

    Returns: 8

  81. 500

    2

    4

    Returns: 491

  82. 10000

    2

    3

    Returns: 990

  83. 1

    5

    5

    Returns: 0

  84. 4

    2

    8

    Returns: 0

  85. 11

    2

    2

    Returns: 2

  86. 40

    1

    1

    Returns: 9

  87. 1

    2

    2

    Returns: 0


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: