Palindromic number

how do i write a program for (For a given integer X, consisting of not more than 6 digits, write the value of the largest palindrome smaller than X and the value of the smallest palindrome larger than X to output.)

The next palindrome question is essentially PALIN.
The idea for both cases is “how to do a minimum change in the existing string to make it a palindrome?”. Break the string into first and second halves. Try to make cases, eg “this is the correct position decreasing which can yields a smaller palindrome”. Focus on the left part; after an increase in any digit on the left all digits on the right can be adjusted. Also take care of the case where the given string is already a palindrome; the answers for cases are different from the given string.

1 Like