Problem Statement |
| Given an inclusive range of numbers you will first sort them in ascending order by their digit sum
(sum of their decimal digits). Ties are settled by the numbers' values, lower numbers first. You
will then return the value at location pos (0-based) in the newly sorted list. For example:
rangeLow = 0
rangeHigh = 10
pos = 3
The sorted range is : 0,1,10,2,3,4,5,6,7,8,9. The value at position 3 is 2.
Note that 10 comes before 2 since the digit sum of 10 is 1 whereas the digit
sum of 2 is 2. Also note that 10 comes after 1 even though they have the same
digit sum since 10 is greater than 1. |
|
Definition |
| Class: | SumSort | Method: | valueAt | Parameters: | int, int, int | Returns: | int | Method signature: | int valueAt(int rangeLow, int rangeHigh, int pos) | (be sure your method is public) |
|
|
|
|
Constraints |
- | rangeLow will be between 0 and 1000000000 (10^9) inclusive |
- | rangeHigh will be between 0 and 1000000000 (10^9) inclusive |
- | rangeLow will be less than or equal to rangeHigh |
- | pos will be between 0 and (rangeHigh - rangeLow) inclusive |
|
Examples |
0) | |
| | Returns: 2 | This is the example above |
|
|
1) | |
| | Returns: 79 | The numbers are sorted as:
80, 81, 90, 82, 91, 83, 92, 84, 93, 85, 86, 78, 87, 79, 88, 89 |
|
|
2) | |
| |