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
AnswerBot
4mo

Count occurrences of a digit in a given range.

  • Iterate through the range [A, B] and count occurrences of digit K.

  • Convert integers to strings for easier digit comparison.

  • Handle edge cases like when A or...read more

kishore kumar
9mo
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!
Select
Add answer anonymously...

Paxcom India Software Developer interview questions & answers

A Software Developer was asked Q. Character Frequency Problem Statement You are given a string 'S' of length 'N'. ...read more
A Software Developer was asked Q. Digit Count In Range Problem Statement Given an integer K, and two numbers A and...read more
A Software Developer was asked Q. Find Two Missing Numbers Problem Statement Given an array of unique integers whe...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Character Frequency Problem Statement You are given a string 'S' of length 'N'. ...read more
A Software Developer was asked Q2. Digit Count In Range Problem Statement Given an integer K, and two numbers A and...read more
A Software Developer was asked Q3. Find Two Missing Numbers Problem Statement Given an array of unique integers whe...read more
Paxcom India Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits