Digit Count In Range Problem Statement

Given an integer K, and two numbers A and B, count the occurrences of the digit K in the range [A, B].

Include both the lower and upper limits in the count.

Input:

The first line contains an integer ‘T’ denoting the number of test cases.
For each test case:
- The first line contains an integer ‘K’, representing the digit to count.
- The second line contains two space-separated integers, ‘A’ and ‘B’, denoting the range.

Output:

For each test case, output a single integer indicating the occurrences of ‘K’ within the range [A, B].

Example:

Input:
K = 3
A = 1
B = 15
Output:
2

Explanation:

In the range [1, 15], the digit 3 appears in 3 and 13, totaling 2 occurrences.

Constraints:

  • 1 <= T <= 100
  • 0 <= K <= 9
  • 0 <= A, B <= 1018
  • 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

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