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.

AnswerBot
4mo

The task is to find the smallest palindrome greater than a given number.

  • Iterate from the middle of the number and mirror the left side to form the palindrome.

  • Handle cases where the number is already a...read more

Ankita Pandey
2y

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);

}

}

Help your peers!
Select
Add answer anonymously...

SPRINKLR Full Stack Engineer interview questions & answers

A Full Stack Engineer was asked Q. Rank from Stream Problem Statement Given an array of integers ARR and an integer...read more
A Full Stack Engineer was asked Q. Smaller Elements Count Problem Statement Given an array of size N, return a coun...read more
A Full Stack Engineer was asked Q. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more

Popular interview questions of Full Stack Engineer

A Full Stack Engineer was asked Q1. Rank from Stream Problem Statement Given an array of integers ARR and an integer...read more
A Full Stack Engineer was asked Q2. Smaller Elements Count Problem Statement Given an array of size N, return a coun...read more
A Full Stack Engineer was asked Q3. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
SPRINKLR Full Stack Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits