Digit Count In Range

You are given an integer ‘K’, and two numbers ‘A’ and ‘B’. You need to count the occurrences of the given digit ‘K’, in the range [A, B].

Note:
 You need to count occurrences at every place of the number. You also need to include the lower and higher limits of the given range
For example :
Given K = 3, A = 1, B = 15, then 3 occurs 2 times(3, 13) in the range [1, 15], so you need to print 2.
Input Format:
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.

The first line of each test case contains a single integer ‘K’, denoting the digit of which you need to count the occurrences.

The second line of each test case contains two space-separated integers, ‘A’ and ‘B’, denoting the lower and higher limits of the range in which you need to count the occurrence.
Output Format:
For each test case, you need to print a single integer that denotes occurrences of ‘K’ in the range [A, B].

Print the output of each test case in a separate line.
Note:
You don’t need to print anything; It has already been taken care of.
Constraints:
1 <= T <= 100
0 <= K <= 9
0 <= A, B <= 10^18

where ‘T’ is the number of test cases, ‘K’ is the digit and ‘A’ and ‘B’ are the two integers.

Time limit: 1 sec
kishore kumar
4mo
student at
Saranathan College of Engineering, Tiruchirapalli
/ * java solution: public static void main(String[] args) { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); int base=10; char init=Character.forDigit(k,base); int a=sc.nextInt(); int b=sc.nextI...read more
Help your peers!
Add answer anonymously...
Paxcom India Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter