<p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>

<p><strong>Note:</strong>&nbsp;You must not use any built-in BigInteger library or convert the inputs to integer directly.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> num1 = "2", num2 = "3"
<strong>Output:</strong> "6"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> num1 = "123", num2 = "456"
<strong>Output:</strong> "56088"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= num1.length, num2.length &lt;= 200</code></li>
	<li><code>num1</code> and <code>num2</code> consist of digits only.</li>
	<li>Both <code>num1</code> and <code>num2</code>&nbsp;do not contain any leading zero, except the number <code>0</code> itself.</li>
</ul>

/*
Ques to ask:
    - Can number contain leading 0?
    - Can number be negative?
    - Can number empty i.e ""?

Sol:
=> Elementary maths : [TIME - O(N+M) SPACE - O(N+M)]
-> N : no of digits in num1
-> M : no of digits in num2
    - Check if num1 or num2 is '0' or not, if it is then return 0
    - Multiply every digit of num2 (from end) to whole num1 & the resultant product will be padded with 0 at the end [number of zeros = 10^(len(num2) - i - 1)] then add all these product formed & return ans.
*/
class Solution {
public:
    string add(string num1, string num2) {
        if(num2.size() < num1.size())swap(num1, num2);
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        int n = num1.size();
        int carry = 0 ;
        string ans = "";

        for(int i = 0 ; i < n ; i++){
            int temp = (num1[i]-'0') + (num2[i]-'0') + carry ;
            ans += to_string(temp%10) ;
            carry = temp/10;
        }

        for(int i = n; i< num2.size(); i++){
            int temp = (num2[i]-'0') + carry ;
            ans += to_string(temp%10) ;
            carry = temp/10;
        }
        if(carry != 0)ans += to_string(carry);
    
        reverse(ans.begin(), ans.end());
        return ans;
    }

    string multiplyChar(string s, char c){
        string ans = "" ;
        int carry = 0;

        for(int i = 0 ; i < s.size(); i++){
            int temp = (s[i] - '0')*(c - '0') ;
            temp += carry ;
            ans += (temp%10) + '0' ;
            carry = temp/10 ;
        }
        if(carry != 0) ans += to_string(carry) ;
        
        reverse(ans.begin(), ans.end());
        return ans ;
    }

    string multiply(string num1, string num2) {
        if(num1 == "0" || num2 == "0")return "0";
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        string ans = "" ;
        string zeros = "" ;

        for(int i = 0 ; i < num2.size(); i++){
            string temp = multiplyChar(num1, num2[i]);

            if(ans == "") ans = temp ;
            else{
                zeros += '0' ;
                temp += zeros ;
                ans = add(ans,temp);
            }

            cout << ans << " " << temp << endl ;
        }

        //reverse(ans.begin(), ans.end());

        return ans;
    }
};
17934