Back to problems

Smallest Palindromic Number Not Less Than N

Algorithm · Uber · Medium

You are given a string n made of decimal digits that encodes a non-negative integer. Find the least palindromic number whose value is at least n, and return it as a string. A number is a palindrome when its digits are identical whether read forwards or backwards. Only palindromes that are not below the given number are candidates. Concretely: When n is itself a palindrome, the answer is n unchanged. Otherwise, the answer is the smallest palindrome whose value is strictly…

Loading the rest of the question…