You are not logged in. Please login at to post your questions!


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;
        if(a == b){
            return true;
            return false;

    lo nextPal(lo p){
        while(true) {
            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;


asked 28 Jul '17, 04:02

jaycram's gravatar image

accept rate: 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 :)


answered 28 Jul '17, 04:47

liaojh's gravatar image

accept rate: 7%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 28 Jul '17, 04:02

question was seen: 307 times

last updated: 28 Jul '17, 04:47