Given a positive number n, print a number less than n such that all its digits are distinct.
Input : 1134 Output : 1098 1098 is the largest number smaller than 1134 such that all digits are distinct. Input : 4559 Output : 4539
The problem can easily be solved by using counting. Firstly, loop through numbers less than n and for each number count the frequency of the digits using count array. If all the digits occur only once than we print that number. The answer always exists so there is no problem of infinite loop.
- Print a number containing K digits with digital root D
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find the smallest number whose digits multiply to a given number n
- Find maximum number that can be formed using digits of a given number
- Number of digits to be removed to make a number divisible by 3
- Build Lowest Number by Removing n digits from a given number
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Count number of digits after decimal on dividing a number
- Find count of digits in a number that divide the number
- Number of digits in the nth number made of given four digits
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check if a number with even number of digits is palindrome or not
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.