CSES - Number sequence

Consider the sequence of numbers, where each number is the smallest positive integer that does not appear earlier in the sequence and that contains the same digit at least twice.

The sequence starts like this:

11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 101, 110, 111, 112, 113, 114, \dots

Your task is to compute the number at position n in the sequence. You may assume that n is at most 1000.

In a file sequence.py, implement the function generate that returns the specified element of the sequence.

def generate(n):
    # TODO

if __name__ == "__main__":
    print(generate(1)) # 11
    print(generate(2)) # 22
    print(generate(3)) # 33
    print(generate(10)) # 100
    print(generate(123)) # 505