Problem Statement
An auxanometer is a device inside a medical cabinet used for measuring height. It is divided vertically into equal 1 centimeter segments. The segments are labeled differently on each side of the device. The left side is used to measure the height of an adult standing on the floor, and the right side is used to measure the height of a child standing on a footstool directly beneath the device. The segments on the left side are labeled nmin to nmax, inclusive, from bottom to top. The segments on the right side are labeled 1 to nmax-nmin+1, inclusive, from bottom to top.
Your task is to determine the number of segments where the concatenation of the number on the left and the number on the right forms a non-decreasing sequence of digits. For example, if the number on the left is 168 and the number on the right is 89, the concatenation is 16889, a non-decreasing sequence of digits. Return the number of such segments on the given auxanometer.
Definition
- Class:
- Auxanometer
- Method:
- countIncreasingMarks
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int countIncreasingMarks(int nmin, int nmax)
- (be sure your method is public)
Constraints
- nmin and nmax will be between 1 and 10^9, inclusive.
- nmin will be strictly less than nmax.
Examples
1
9
Returns: 9
Here, the numbers on the left and right are the same. They both go from 1 to 9, so their concatenations are 11, 22, ..., 99, all of which are non-decreasing sequences of digits.
2
10
Returns: 0
Here, the numbers on the left side go from 2 to 10, and the corresponding numbers on the right side go from 1 to 9. None of the concatenations (21, 32, ..., 98, 109) are non-decreasing sequences of digits.
1090
1112
Returns: 2
There are only two satisfactory segments here: 1111-22 and 1112-23.
80
169
Returns: 13
111
222
Returns: 9
2
100000
Returns: 0
11111
67890
Returns: 9
1
1000000
Returns: 54
10
2345678
Returns: 8
1000000
100000000
Returns: 8
1
1000000000
Returns: 81
1001
327943200
Returns: 9
11111
124523232
Returns: 9
111111111
222222222
Returns: 9
999999999
1000000000
Returns: 0
100000000
1000000000
Returns: 8
400000
999999999
Returns: 7
4327
563067346
Returns: 5
10001
1000001
Returns: 9
67352345
99934352
Returns: 0
100000000
999999999
Returns: 8
80993
239217726
Returns: 0
890
1000000000
Returns: 22
15778
1000000000
Returns: 16
568
1000000000
Returns: 31
166566668
1000000000
Returns: 82
15666668
1000000000
Returns: 122
57777779
1000000000
Returns: 125
66644446
1000000000
Returns: 165
66666657
1000000000
Returns: 285
66666668
1000000000
Returns: 405
55555557
1000000000
Returns: 495
3
5
Returns: 0
17
99999999
Returns: 5
80
1000000000
Returns: 14
5
1000000000
Returns: 3
78
99999999
Returns: 15
1
999999999
Returns: 81