Here is what I needed previously


#1

Comment body goes here.


#2

/* the modulo of a number is mod[number]=(mod[number_excluding_last_digit]*10 + last_digit)%N */

string Solution::multiple(int A) {
if(A==1)return “1”;
queue qu;
vector r_p(A,-1);//remainder at parent state
vector c_s(A,-1);//last digit of curr no i.e the step I have taken
qu.push(1);
while(!qu.empty()){
int curr =qu.front();
if(curr==0)break;
qu.pop();

    int next_1=(curr*10+0)%A;//first possible
    if(r_p[next_1]==-1){
         qu.push(next_1);
         r_p[next_1]=curr;//think......
        c_s[next_1]=0;//last digit of curr no will be 0
    }
    
    int next_2=(curr*10+1)%A;//second possible
    if(r_p[next_2]==-1){
         qu.push(next_2);
         r_p[next_2]=curr;//think......
        c_s[next_2]=1;//last digit of curr no will be 1
    }
     
  
    
}

vector n;

//contructs the string in reverse order

for(int r=0;r!=1;r=r_p[r]){
n.push_back(‘0’+c_s[r]);

}
n.push_back(‘1’);
reverse(n.begin(),n.end());

return string(n.begin(),n.end());

}