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
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.
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.
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.
10000000
8
8
Returns: 1
Label 10000000 is the only one here of length 8.
2718317
3
7
Returns: 2718218
10000000
1
8
Returns: 10000000
9999999
7
8
Returns: 9000000
42
2
2
Returns: 33
4
1
2
Returns: 4
4560
3
5
Returns: 4461
596427
1
7
Returns: 596427
2
1
2
Returns: 2
35631
2
6
Returns: 35622
8319
2
4
Returns: 8310
7
1
2
Returns: 7
49
2
3
Returns: 40
44063
4
6
Returns: 43064
8
1
2
Returns: 8
59
3
3
Returns: 0
4351423
4
7
Returns: 4350424
75291
5
6
Returns: 65292
78363
2
5
Returns: 78354
950193
4
4
Returns: 9000
790027
2
3
Returns: 990
60078
1
5
Returns: 60078
31
2
2
Returns: 22
2349
4
4
Returns: 1350
949
1
4
Returns: 949
538
3
4
Returns: 439
2763
2
5
Returns: 2754
3562947
5
8
Returns: 3552948
6028964
6
7
Returns: 5928965
28
1
3
Returns: 28
550516
1
5
Returns: 99999
9780322
5
7
Returns: 9770323
45516
1
2
Returns: 99
5645825
2
4
Returns: 9990
52
3
3
Returns: 0
9
1
1
Returns: 9
3171926
1
5
Returns: 99999
2771431
1
1
Returns: 9
7
1
1
Returns: 7
10
3
3
Returns: 0
8242164
5
8
Returns: 8232165
5323
2
4
Returns: 5314
2554198
1
8
Returns: 2554198
79379
1
6
Returns: 79379
427
3
3
Returns: 328
7
1
1
Returns: 7
915
1
4
Returns: 915
421
3
4
Returns: 322
3
2
2
Returns: 0
9496898
4
6
Returns: 999000
8
2
2
Returns: 0
6430534
1
6
Returns: 999999
234
1
1
Returns: 9
828718
4
7
Returns: 827719
10000000
2
8
Returns: 9999991
10000000
1
1
Returns: 9
1
1
1
Returns: 1
9999999
1
7
Returns: 9999999
10
1
1
Returns: 9
10000
2
2
Returns: 90
990
1
4
Returns: 990
999999
3
4
Returns: 9900
100000
1
1
Returns: 9
1114
1
1
Returns: 9
10000000
5
5
Returns: 90000
9976876
3
7
Returns: 9976777
152356
2
3
Returns: 990
1
2
3
Returns: 0
1000
2
2
Returns: 90
999
1
1
Returns: 9
2718317
1
1
Returns: 9
95
2
2
Returns: 86
99
3
7
Returns: 0
15
1
2
Returns: 15
10000000
4
8
Returns: 9999001
10000000
1
3
Returns: 999
8
1
1
Returns: 8
500
2
4
Returns: 491
10000
2
3
Returns: 990
1
5
5
Returns: 0
4
2
8
Returns: 0
11
2
2
Returns: 2
40
1
1
Returns: 9
1
2
2
Returns: 0