Palin Problems

This problem is killing me: My solution is very straight forward and doesnt seem to exceed time limit: it simply goes through every number bigger than K and checks if its a palindrome, but I keep on getting wrong answers. Every test case ive thrown at it has worked. Please help.

using namespace std;
    #include <iostream>
    #include <string>
    #include <algorithm>
    #define lo unsigned long long
    
    
    //queue all data
    //systematically go through and solve
    
    bool palin(lo p) {
        string a = std::to_string(p);
        string b = a;
        reverse(b.begin(),b.end());
        if(a == b){
            return true;
        }
        else{
            return false;
        }
    
    }
    lo nextPal(lo p){
        while(true) {
            p++;
            if (palin(p)) {
                return p;
            }
        }
    }
    int main() {
    
        lo T;
        cin >> T;
        lo a;
        for (lo x = 0;x<T;x++){
            cin >> a;
            cout << nextPal(a)<<endl;
        }
    
        return 0;
    
    }

So the problem is asking for the first number bigger than K that is a palindrome. What is the constraint on K?

For me, your code TLE on where K \geq 10^{13}.

You can use your brute force and come up with a greedy solution :slight_smile: