The Next Year with Distinct Digits
InterviewTime limit1sMemory limit128 MB
Given a year Y, print the smallest year greater than Y whose decimal digits are all distinct.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
2013 is the first year since 1987 in which all digits are distinct. The years 2014, 2015, 2016, 2017, 2018, and 2019 also have all distinct digits. The year 2012, however, does not, because the digit 2 appears twice.
Given a year , find the earliest year greater than in which every digit is distinct.
Input
The first line contains a single integer , the starting year. ()
Output
Print the earliest year greater than in which every digit is distinct.