Find the Kth smallest odd length palindrome number | Function to find the Kth smallest odd length palindrome number ; Store the original number K ; Removing the last digit of K ; Generate the palindrome by appending the reverse of K except last digit to itself ; Find the remainder ; Add the digit to palin ; Divide K by 10 ; Return the resultant palindromic number formed ; Driver Code
def oddLengthPalindrome ( K ) : NEW_LINE INDENT palin = K NEW_LINE K = K // 10 NEW_LINE while ( K > 0 ) : NEW_LINE INDENT rev = K % 10 NEW_LINE palin = palin * 10 + rev NEW_LINE K = K // 10 NEW_LINE DEDENT return palin NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 504 NEW_LINE print ( oddLengthPalindrome ( K ) ) NEW_LINE DEDENT