Back to problems

Smallest Palindrome Strictly Greater Than K

Algorithm · Two Sigma · Hard

A positive integer is called a palindrome when its ordinary decimal representation contains no leading zero and remains unchanged after its digits are reversed. For instance, 5, 33, 262, and 5115 are palindromes, while 40 and 230 are not. For a given positive integer K, return the least integer p such that $$p > K$$ and p is a palindrome. Example 1: Explanation: 43 is not a palindrome, so 44 is the first palindrome greater than 42. Example 2: Explanation: 191 lies below 198,…

Checking your access…