Simple and sweet solnn


#1

string Solution::multiple(int A)
{
pair<int,int> arr[A];
for(int i=0;i<A;i++)
arr[i] = {-2,-2};
queue q;
q.push(1%A);
arr[1%A] = {-1,1};
pair<int,int> t = {-2,-2};
while(!q.empty())
{
int a = q.front();
q.pop();

    int b = (a*10 + 0)%A;
    int c = (a*10 + 1)%A;
    
    if(arr[b] == t)
     {
         arr[b] = {a,0};
         q.push(b);
     }
    if(arr[c] == t)
     {
         arr[c] = {a,1};
         q.push(c);
     }
    
}
string str = "";
int i=0;
while(i!=-1)
{
    pair<int,int> s = arr[i];
    str += to_string(s.second);
    i = s.first;
}
reverse(str.begin(),str.end());
return str;

}