When I run with the following code (C++):
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
void printNextPal(long int i)
{
while (true)
{
string s1 = to_string(i);
string s2 = to_string(i);
reverse(s2.begin(),s2.end());
if (s1 == s2)
{
cout<<s1<<endl;
break;
}
i++;
}
}
int main() {
int t;
long int i;
cin >> t;
while (t--)
{
cin >> i;
printNextPal(i);
}
return 0;
}
I get time limit exceeded error.