Lucky Four - Time Limit Exceeded - C++

I attempted the solution in the below way, i am new to codechef, can anyone tell me why i am getting the error time limit exceeded. Have pasted the code below.

#include “iostream”
#include “list”
using namespace std;

int main()
{
list tList;
list::iterator it;
int t, n, x;

cin >> t;

while (t--)
{
    int count = 0;

    cin >> n;
    tList.push_back(n);

    for (it = tList.begin(); it != tList.end(); ++it)
    {
        while (*it != 0)
        {
            x = *it % 10;

            if (x == 4)
            {
                count++;
            }
            *it /= 10;
        }
    }

    cout << count << endl;
}

return 0;

}

Your solution is O(T^2), where T can be as high as 10^5.

Hint: there’s absolutely no need to store each integer: just read it in, process it, print the answer for that integer, and forget it :slight_smile:

Oh yes! Got it thanks. @ssjgz

1 Like