Given an integer N, the task is to find the Nth number made up of odd digits (1, 3, 5, 7, 9) only.
First few numbers made up of odd digits are 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 31, …
Input: N = 7
1, 3, 5, 7, 9, 11, 13
13 is the 7th number in the series
Input: N = 10
Approach 1 (Simple) : Starting from 1, keep checking if the number is made up of only odd digits (1, 3, 5, 7, 9) and stop when nth such number is found.
Below is the implementation of the above approach:
Approach 2 (Queue Based): The idea is to generate all numbers (smaller than n) containing odd digits only. How to generate all numbers smaller than n with odd digits? We use queue for this. Initially we push ‘1’, ‘3’, ‘5’, ‘7’ and ‘9’ to the queue. Then we run a loop while count of processed elements is smaller than n. We pop an item one by one and for every popped item x, we generate next numbers x*10 + 1, x*10 + 3, x*10 + 5, x*10 + 7 and x*10 + 9. We enqueue these new numbers. Time complexity of this approach is O(n)
Please refer below post for implementation of this approach.
Count of Binary Digit numbers smaller than N
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.
- Number of digits in the nth number made of given four digits
- Minimum number closest to N made up of odd digits only
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find the n-th number made of even digits only
- Finding n-th number made of prime digits (2, 3, 5 and 7) only
- Smallest multiple of a given number made of digits 0 and 9 only
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Sum of the digits of square of the given number which has only 1's as its digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of Rectangles with area K made up of only 1s from given Binary Arrays
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Minimum digits to be removed to make either all digits or alternating digits same
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Program to find Nth odd Fibonacci Number
- Program to find last two digits of Nth Fibonacci number
- Find Nth even length palindromic number formed using digits X and Y
- Nth positive number whose absolute difference of adjacent digits is at most 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.