<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>

class Solution {
public:
    string multiply(string num1, string num2) {
        string up = "";
        string down = "";
        if (num1.length() > num2.length()) {
            up = num1;
            down = num2;
        } else {
            up = num2;
            down = num1;
        }

        vector<string> toSum;
        string partialRes = "";
        int rem = 0;
        int n = 0;
        for (int i = down.length() - 1; i >= 0; i--) {
            int d = down[i] - '0';
            n++;
            rem = 0;
            partialRes = "";  // Reset here instead of at the end
            for (int j = up.length() - 1; j >= 0; j--) {
                int u = up[j] - '0';
                int res = d * u + rem;
                rem = res / 10;  // Calculate remainder for next iteration
                partialRes = to_string(res % 10) + partialRes;
            }
            if (rem > 0) {
                partialRes = to_string(rem) + partialRes;  // Add any remaining carry
            }
            toSum.push_back(partialRes + string(n - 1, '0'));  // Add trailing zeros
        }

        // Summing all parts
        string totalSum = "";
        rem = 0;
        int maxLen = toSum.back().length();
        for (int i = 0; i < maxLen; ++i) {
            int columnSum = rem;
            for (int j = 0; j < toSum.size(); ++j) {
                int idx = toSum[j].length() - 1 - i;
                if (idx >= 0) {
                    columnSum += toSum[j][idx] - '0';
                }
            }
            totalSum = to_string(columnSum % 10) + totalSum;
            rem = columnSum / 10;
        }

        if (rem > 0) {
            totalSum = to_string(rem) + totalSum;  // Add remaining carry if any
        }

        // Remove leading zeros
        while (totalSum.length() > 1 && totalSum[0] == '0') {
            totalSum.erase(totalSum.begin());
        }

        return totalSum;
    }
};

32136