# Code failing for larger test cases

#1

My code showing error for a test case:
5131848155574784703269632922904933776792735241197982102373370
56675688419586288442134264892419611145485574406534291250836

string Solution::multiply(string A, string B)
{
string ans="",temp;
int j,k,res,i;
if(A==“0” || B==“0”)
return “0”;
for(int l=B.size()-1;l>=0;l–)
{
j=B.size()-1;
temp="";
while(j–>l)
temp.push_back(‘0’);

``````    k=B[l]-'0';
res=0;
for(j=A.size()-1;j>=0;j--)
{
res=res+(k*(A[j]-'0'));
temp.push_back(res%10+'0');
res=res/10;
}
if(res>0)
temp+=to_string(res);
//return temp;
if(ans=="")
ans=temp;
else
{
i=0;
res=0;
while(i<temp.size()&& i<ans.size())
{
res=res+(temp[i]-'0')+(ans[i]-'0');
ans[i]=res%10 + '0';
res=res/10;
i++;
}
if(i<temp.size())
{
res=res+(temp[i]-'0');
ans.push_back(res%10 + '0');
res=res/10;
i++;
}
if(i<ans.size())
{
res=res+(ans[i]-'0');
ans[i]=res%10 + '0';
res=res/10;
i++;
}
if(res>0)
ans+=to_string(res);
//return ans;
}
}
temp="";
for(int i=ans.size()-1;i>=0;i--)
temp.push_back(ans[i]);

return temp;
``````

}