Find the first year after a given year that has all distinct digits.
You are given a year . Your task is to find the smallest year strictly greater than such that all four digits of the year are different.
For example, 1987 is beautiful because its digits are all distinct, while 2013 is not because the digit 0 appears twice? Actually 2013 is beautiful; the condition is simply that no digit repeats.
Return the first year after the given one that satisfies this property.
A single integer representing the starting year.
Print the smallest year greater than whose digits are all different.
Example 1
Input
1987
Output
2013
Explanation
1988, 1989, ..., 2012 are not beautiful. The next year with all distinct digits is 2013.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.