We say that a year is legal if its decimal representation does not contain repeated digits. For example, all years from 2013 to 2019 are legal. However, 2020 and 2344 are not legal.

a) Find the next sequence of 7 consecutive legal years after 2019.

b) Is it possible in the future, starting from the year 2016, to have a sequence with more than 7 consecutive legal years?
Solution

a) Let's initially look for, within the 21st century, if there is a sequence of consecutive legal years with 7 terms. Since the hundreds digit is 0 and the thousands digit is 2, the first term of the sequence cannot have the units digit as the numbers 0, 1, and 2, as inevitably some of the next terms would have repeated digits. If one of the intermediate terms of the sequence is less than 2090, it also cannot end in 9, as the next term would end in 0. Consequently, the legal sequence must have the following format:

$$
\overline{20 \star 3}, \overline{20 \star 4}, \overline{20 \star 5}, \overline{20 \star 6}, \overline{20 \star 7}, \overline{20 \star 8}, \overline{20 \star 9}
$$

One of the digits $\{3,4,5,6,7,8,9\}$ will be equal to the tens digit, and this shows that there is no other legal sequence before 2090. Analyzing the next 13 years, we can find the sequence: 2103, 2104, 2105, 2106, 2107, 2108, and 2109.

b) Suppose there is a sequence in the future with more than 7 consecutive legal years. Years after 2016 have at least 4 digits, and a sequence of legal numbers cannot contain a number ending in 99, as in this case the number would have two identical digits. Therefore, the hundreds digit is always the same in all numbers of the sequence. We must now consider two cases:

1) When the tens digits of the numbers in the sequence are the same: In this case, the last four digits of the numbers in the sequence have the form $\overline{a b c \star}$, where the symbols $a, b$, and $c$ indicate the digits of the decimal representation that do not change between the members of the sequence, and the symbol $\star$ indicates the units digit. Since there are only 10 possible digits, namely the elements of the set $\{0,1,2, \ldots, 9\}$, once the digits $a, b$, and $c$ have been fixed, there are only $10-3=7$ options for the digit $\star$. This prevents a sequence with more than 7 legal years in this case.
2) When there is a change in the tens digit of the numbers in the sequence: Suppose the last four digits of the first number in the legal sequence are of the form $a b c d$. For a change in the tens digit to occur within the sequence, we must have $c \neq 9$, as in this case, immediately after the change, a number ending in 00 would appear in the sequence and thus it would not be legal. Thus, the first 8 numbers in the sequence would be of the form:

$$
\overline{a b c d}, \overline{a b c(d+1)}, \ldots, \overline{a b c 9}, \overline{a b(c+1) 0}, \ldots, \overline{a b(c+1)(d-2)}
$$

Again, the digits that appear in the last two positions of the decimal representation must be in the set $\{0,1,2,3, \ldots, 9\}$ and cannot be equal to $a$ and $b$. This gives us only 8 options. Moreover, the digits in the set $\{d, d+1, \ldots, 9\}$ cannot be equal to $c$, and the digits in the set $\{0,1,2, \ldots, d-2\}$ cannot be equal to $c+1$. For these 8 years to be legal, we must have $c+1 \in\{d, d+1, \ldots, 9\}$ and $c \in\{0,1,2, \ldots, d-2\}$. This results in the appearances of the endings $a b c(c+1)$ and $a b(c+1) c$ among the elements of the sequence. Since all 10 possible digits appear among the consecutive two-digit numbers $\overline{c(c+1)}, \overline{c(c+2)}, \ldots, \overline{(c+1) c}$, we can conclude that some element of this sequence will not be legal by repeating either the digit $a$ or the digit $b$.

In both of the above cases, we conclude that it is not possible for there to be a sequence of consecutive legal years with more than 7 terms, so the answer to this item is "no".

Note: We are using a bar to distinguish the four-digit number $\overline{a b c d}$ from the product $a \cdot b \cdot c \cdot d$. For example, if $\overline{a b c d}=1267$, then $a=1, b=2, c=6$, and $d=7$.