Problem title
Difficulty
Avg time to solve

Rearrange Array
Easy
15 mins
Find the Winner
Easy
10 mins
Custom Sort String
Easy
10 mins
Battalions and tanks
Moderate
10 mins
Mirror String
Easy
15 mins
Find the K-th Smallest Element in Array
Easy
10 mins
Median of a row wise sorted matrix
Moderate
30 mins
Minimum Number Of Swaps For Bracket Balancing
Moderate
15 mins
Minimum Rotations
Easy
10 mins
Rotate DLL
Moderate
10 mins
1

Count Numbers With Equal First and Last Digit

Difficulty: MEDIUM
Contributed By
Avg. time to solve
15 min
Success Rate
77%

Problem Statement

Ninja has given a range represented by two positive integers ‘L’ and ‘R’. Find the count of numbers in the range where the first digit is equal to the last digit of the number.

Ninja called you for help as you are his only friend. Help him to solve the problem.

Example :
Input: 'L' = 9 , ‘R’ = 12

Output: "2"

As ‘9’ and ‘11’ are the only numbers that have their first digit equal to the last digit. So the answer is ‘2’.
Input Format :
The first line will contain the integer 'T', denoting the number of test cases.

Each test case contains two space-separated integers ‘L’ and ‘R’. 
Output format :
For each test case, print the number of integers in [L, R] such that their first digit is equal to the last digit in those integers.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= 'T' <= 1000
1 <= ‘L’ <= ‘R’ <= 10^18
Time Limit: 1 sec
Sample Input 1 :
2
8 12
19 35
Sample Output 1 :
3
2
Explanation Of Sample Input 1 :
In test case ‘1’. There are ‘3’ numbers satisfying the requirement that are ‘8’, ‘9’ and ‘11’. 
In test case ‘2’. There are ‘2’ numbers satisfying the requirement that are ‘22’ and ‘33’.
Sample Input 2 :
2
1 20
1 100
Sample Output 2 :
10
18
Reset Code
Full screen
copy-code
Console