Next Smallest Palindrome Problem Statement
Given a string representation of a number 'S', determine the smallest palindrome that is strictly greater than this number 'N'.
Example:
Input:
3
2
99
3
123
4
4567
Output:
101
131
4664
Explanation:
The first input '99' has the next palindrome as '101'. The second input '123' results in '131', and for '4567', it is '4664'.
Constraints:
1 <= T <= 100
1 <= len(S) <= 10^4
Note: The length of string 'S' indicates the number of digits in number 'N'. A single digit or multi-digit number can be a palindrome.
import java.io.*;
class GFG
{
{
int n, k, rev = 0;
n = num;
while (num != 0) {
k = num % 10;
rev = (rev * 10) + k;
num = num / 10;
}
// check if num and its reverse are same
if (n == rev) {
return 1;
}
else {
return 0;
}
}
public static void main(String[] args)
{
int num = 9687;
while (isPalindrome(num) == 0) {
num = num + 1;
}
System.out.print("Next Palindrome : ");
System.out.print(num);
}
}
Top SPRINKLR Full Stack Engineer interview questions & answers
Popular interview questions of Full Stack Engineer
Reviews
Interviews
Salaries
Users/Month