I am trying to solve the problem Next Palindrome and got an TLE.
Please help me reduce the time.
Here is my Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,i;
cin>>t;
while(t–)
{
int n,m;
string s;
cin>>n;
for(i=n+1;i<=1000000;i++)
{
s=to_string(i);
string s2=s;
reverse(s2.begin(),s2.end());
if(s2==s)
{
cout<<s2<<endl;
break;
}
}
}
return 0;
}