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.
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.
- Print all numbers in given range having digits in strictly increasing order
- Print all numbers less than N with at-most 2 unique digits
- Count of integers of length N and value less than K such that they contain digits only from the given set
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Check if a given number is one less than twice its reverse
- Print all Prime Quadruplet of a number less than it
- Check if the sum of digits of number is divisible by all of its digits
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Count of Array elements greater than all elements on its left and next K elements on its right
- Count of Array elements greater than all elements on its left and at least K elements on its right
- Print all Semi-Prime Numbers less than or equal to N
- Print all Strong numbers less than or equal to N
- Print all proper fractions with denominators less than equal to N
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Numbers less than N which are product of exactly two distinct prime numbers
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Find the largest composite number that divides N but is strictly lesser than N
- Smallest even digits number not less than N
- Smallest odd digits number not less than N
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.