A Beautiful Year

Practice this coding question on Coding Gurukul.

Problem statement

A campus archive designs an annual commemorative stamp using the four decimal digits of a year. The designer wants a future year whose digits are all different so that no digit-shaped stamp block has to be reused. The current year is not eligible, even if it already has distinct digits. Your task is to find the next eligible year for the archive’s schedule. Your task Given y, find the smallest integer year strictly greater than y whose decimal representation contains no repeated digit. Examine the entire year number: two matching digits in any positions make a candidate unsuitable. Print the first future year that satisfies the rule. Important details The comparison is strictly greater, not greater than or equal. Zero is a digit and must also be unique if present. The stated range guarantees a four-digit answer exists. Worked example After 2024, years through 2030 repeat a digit. The year 2031 uses 2, 0, 3 and 1 exactly once, so it is the first eligible year.

Input format

One integer y.

Output format

Print the next year with all distinct digits.

Constraints

1000 <= y <= 9000.

Sample input

2024

Sample output

2031

Sign in to run or submit a solution in C++, Java or Python.