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.
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
- Find Next number having distinct digits from the given number N
- Next Number with distinct digits
- C Program to Print all digits of a given number
- 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 under given constraints
- Find the Largest number with given number of digits and sum of digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Find smallest number with given number of digits and sum of digits
- Number of distinct ways to represent a number as sum of K unique primes
- Find smallest possible Number from a given large Number with same count of digits
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find the largest composite number that divides N but is strictly lesser than N
- Count number of digits after decimal on dividing a number
- Count of prime digits of a Number which divides the number
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.