Problem: Palindrome Check + Next Larger Palindrome
Part 1: Palindrome validation
Given a string s, determine whether s is a palindrome (reads the same forward and backward).
-
Return
true
if
s
is a palindrome, otherwise
false
.
-
Assume
s
contains only alphanumeric characters and is case-sensitive unless you explicitly normalize.
Part 2: Next larger palindrome number
Given a non-negative integer x (potentially very large), return the smallest palindrome number strictly greater than x.
Because x may exceed 64-bit range, treat x as a string.
Input/Output
-
Input:
s
(string) for Part 1;
x
(string representing a non-negative integer) for Part 2
-
Output:
boolean for Part 1; string for Part 2
Constraints (assume for interview)
-
1 <= len(s) <= 2 * 10^5
-
1 <= len(x) <= 2 * 10^5
-
x
has no leading zeros unless
x == "0"
Examples
Part 1:
-
s = "racecar"
->
true
-
s = "ab"
->
false
Part 2:
-
x = "123"
->
"131"
-
x = "99"
->
"101"
-
x = "808"
->
"818"