Problem Statement
John is testing integer numbers. He has two integers a and b. Suppose he is considering some positive integer number X. If X is between a and b, inclusive, then X passes Johnâs test. Otherwise John will construct integer number Y using digits of the number X. First he will take the first digit (most significant) of X, then the last digit of X, then the second digit of X, then the digit that comes before the last one and so on until he enumerates all digits of X. For example, if X is 1234567 then Y will be 1726354 and if X is 1020 then Y will be 1002. After that if Y is between a and b, inclusive, then X passes Johnâs test. If none of two conditions holds then X fails the test.
Return the number of positive integers that pass Johnâs test. For example, if a=98 and b=102 there are seven positive integers that pass Johnâs test: 98, 99, 100, 101, 102, 110 and 120.
Definition
- Class:
- TheNumberTesting
- Method:
- find
- Parameters:
- long, long
- Returns:
- long
- Method signature:
- long find(long a, long b)
- (be sure your method is public)
Constraints
- a will be between 1 and 10^18, inclusive.
- b will be between a and 10^18, inclusive.
Examples
98
102
Returns: 7
123456789
123456789
Returns: 2
111
111
Returns: 1
4747
4774
Returns: 55