Canadian Computing Competition: 2013 Stage 1, Junior #3, Senior #1
You might be surprised to know that 2013 is the first year since 1987 with distinct digits. The years 2014, 2015, 2016, 2017, 2018, 2019 each have distinct digits. 2012 does not have distinct digits, since the digit 2 is repeated.
Given a year, what is the next year with distinct digits?
Input Specification
The input consists of one integer (), representing the starting year.
Output Specification
The output will be the single integer , which is the next year after with distinct digits.
Sample Input 1
1987
Output for Sample Input 1
2013
Sample Input 2
999
Output for Sample Input 2
1023
Comments
A distinct year will have the length of its digits array/list equal to the length of the set of its digits.
What will happen after the year: 9876543210 ? My algorithm will certainly hang. In order to prolong the happiness we should switch from Decimal number system to some other (more powerful?) one. In Binary system this problem set is very poor.
This one is kinda hard. :)
Create a function to check duplicate which outputs True if there's a duplicate. In that function input is the given string, then loop over the string and create 2 lists to check for duplicate. After that just run a while loop where you increment the year until the duplicate function finds the duplicate. Cheers!
I think you need to do substring comparison of the input. Or convert the input into a list and do element comparison.
bruteforce worked for me, i just incremented by 1 and checked if that year had distinct numbers by converting it into a hashset and comparing the size and the length