Count how many integers from 1 to N contains 0’s as a digit.
Input: n = 9 Output: 0 Input: n = 107 Output: 17 The numbers having 0 are 10, 20,..90, 100, 101..107 Input: n = 155 Output: 24 The numbers having 0 are 10, 20,..90, 100, 101..110, 120, ..150.
The idea is to traverse all numbers from 1 to n. For every traversed number, traverse through its digits, if any digit is 0, increment count. Below is the implementation of the above idea :
Count of numbers from 1 to 107 is 17
Refer below post for optimized solution.
This article is contributed by Dheeraj Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count n digit numbers not having a particular digit
- Count numbers from 1 to n that have 4 as a digit
- Count numbers having 0 as a digit
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1
- Count of N-digit Palindrome numbers
- Count numbers formed by given two digit with sum having given digits
- Count of numbers from the range [L, R] which contains at least one digit that divides K
- Count of N digit numbers possible which satisfy the given conditions
- Count n digit numbers divisible by given number
- Count of N digit palindromic numbers divisible by 9
- Count of N-digit numbers with all distinct digits
- Count numbers with unit digit k in given range
- Count of n digit numbers whose sum of digits equals to given sum
Improved By : Sam007