Find the Kth smallest odd length palindrome number | Function to find the Kth smallest odd length palindrome ; 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
function oddLengthPalindrome ( k ) { let palin = k ; k = Math . floor ( k / 10 ) ; while ( k > 0 ) { let rev = k % 10 ; palin = ( palin * 10 ) + rev ; k = Math . floor ( k / 10 ) ; } return palin ; } let k = 504 ; document . write ( oddLengthPalindrome ( k ) ) ;