Find the first year after a given year that has all distinct digits.
Problem
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.
Input Format
- A single integer — the given year.
Output Format
- Print one integer: the next beautiful year.
Constraints
- The year is a positive integer with 4 digits.
- It is guaranteed that a valid answer exists.
Hints
- Check years one by one starting from .
- For each candidate year, verify whether its digits are all distinct.
Input Format
A single integer representing the starting year.
Output Format
Print the smallest year greater than whose digits are all different.
Constraints
- A solution is guaranteed to exist.
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
Unlock deeper context for this problem
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.