Problem: A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:    * In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.  For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.  You are given a positive integer K. Find the K-th smallest lunlun number.

Submission attempts (in order):
def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            print(inParam+str(item))
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            print(myTupp)
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(input())

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        if mylunlun == K:
            break
    
    if mylunlun == K:
        break

    mydigits += 1


def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(input())

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        
        #     break
    
    if mylunlun == K:
        break

    mydigits += 1


K = int(input())

if K <= 9:
    print(K)
else:
    mylun = 9
    lunList = []

    for indx in range(1, 10):
        lunList.append(str(indx))

    while mylun < K:
        newLunList = []
        for lunItem in lunList:
            if lunItem[len(lunItem)-1] != "0":
                mylun += 1
                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))
                if mylun == K:
                    print(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))
                    break
            
            mylun += 1
            newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1]) ))
            if mylun == K:
                print(lunItem + str( int(lunItem[len(lunItem)-1]) ))
                break

            if lunItem[len(lunItem)-1] != "9":
                mylun += 1
                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))
                if mylun == K:
                    print(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))
                    break
        
        lunList = newLunList


Verdicts: Wrong Answer

Time Limit Exceeded

Accepted