Getting TLE in NUKES

I’m repeatedly getting tle for just one test-case in the que Contest Page | CodeChef and my approach follows as Solution: 58725056 | CodeChef can any one tell why i’m getting tle in this approach??

You missed the n = 0 case.


 if(solLength >= k){
        
        for(ll i=0;i<(2 * k);i++)
            cout << ans[i];
        cout << "\n";
    }

In above code you assumed (and I assumed that you assumed, hehe) that each “value” will be single digit. But just fixing the n = 0 case gets us an AC (almost your code). I think test cases were weak.

To handle that we can count the number of spaces (as you add one spaces per “value”). Look at this code.

1 Like

Yes, got my mistake! Thanks for poining it out😌