Why does this code give TLE?


#1
string Solution::multiple(int A) 
{
    if(A==1)
    return "1";
    string t="1";
    queue<pair<string,int>>q;
    q.push({t,1%A});
    int vis[A]={0};
    while(!q.empty())
    {
        string x=q.front().first;
        int rem=q.front().second;
        q.pop();
        if(rem==0)
        return x;
        else if(vis[rem]!=1)
        {
            vis[rem]=1;
            q.push({x+"0",(rem*(10%A))%A});
            q.push({x+"1",((rem*(10%A))+1)%A});
        }
    }
    return "";
}

#2

Yeah, why did your code got TLE??


#3

really. it has the same complexity and same no of steps. why did this code getting TLE? Maybe its really strict, and pushing pair in queue is taking more time. Still I also not satisfied with this ans. LOL


#4

you can profile this code and compare it with given solution. It will help u to know more.