Given a number N. The task is to find the number of integers from 1 to n which contains digits 0’s and 1’s only.
Input : N = 15 Output : 3 Explanation : 1, 10, 11 are such integers. Input : N = 120 Output : 7 Explanation : 1, 10, 11, 100, 101, 110, 111 are such integers.
Approach: An efficient approach is to build integers which contain 1’s and 0’s only using a recursive function starting from the number 1. For each number check whether it is less than n or not.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Sum of the digits of square of the given number which has only 1's as its digits
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of integers of length N and value less than K such that they contain digits only from the given set
- Check if given number contains a digit which is the average of all other digits
- Number of integers in a range [L, R] which are divisible by exactly K of it's digits
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find a Symmetric matrix of order N that contain integers from 0 to N-1 and main diagonal should contain only 0's
- Find the Largest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Find if it is possible to choose subarray that it contains exactly K even integers
- Minimum number of integers required such that each Segment contains at least one of them
- Minimum number with digits as 4 and 7 only and given sum
- Find the n-th number made of even digits only
- Minimum digits to be removed to make either all digits or alternating digits same
- Find n-th element in a series with only 2 digits (4 and 7) allowed
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.