<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:
//     int n1,n2;
//     // vector<int> ans(10000,0);
//     vector<int> ans = vector<int>(10000, 0);
//     void f(vector<int>& vec1,char c,int j){
//         int d = c-'0';
//         int i=10000-j;
//         int carry = 0;
//         for(int j=n2-1;j>=0;j--){
//             int prod = (vec1[j]*d)+carry;
//             carry=0;
//             if(prod>9){
//                 ans[i] += prod%10;
//                 if(ans[i]>10){
//                     carry += ans[i]/10;
//                     ans[i] = ans[i]%10;
//                 }
//                 i--;
//                 carry += prod/10;
//             }
//         }
//     }
//     string multiply(string num1, string num2) {
//         vector<int> vec1(n1,0);
//         // ans.fill(0);
//         for(int i=0;i<n1;i++){
//             vec1[i] = num1[i]-'0';
//         }
//         // for(int i=0;i<n2;i++){
//         //     vec2[i] = num2[i]-'0';
//         // }

        
//         int j=0;
//         for(int i=n2-1;i>=0;i--){
        
//             f(vec1,num2[i],j);
//             j++;
//         }
//         int idx = -1;
//         for(int i=0;i<10000;i++){
//             if(ans[i]!=0){
//                 idx = i;
//                 break;
//             }
//         }

//         string a="";
//         for(int i=idx;i<1000;i++){
//             // a.append(i+'0');
//             a+=(ans[i]+'0');
//         }

//         return a;

        
//     }
// };
class Solution {
public:
    int n1, n2;
    vector<int> ans;

    // Constructor to initialize the ans vector
    Solution() : ans(10000, 0) {}

    void f(vector<int>& vec1, char c, int j) {
        int d = c - '0';
        int i = 10000 - j - 1; // Corrected the index calculation
        int carry = 0;
        for (int k = n1 - 1; k >= 0; k--) {
            int prod = (vec1[k] * d) + carry;
            carry = prod / 10;
            ans[i] += prod % 10;
            if (ans[i] >= 10) { // Handle carry for the ans array
                ans[i] -= 10;
                carry++;
            }
            i--;
        }
        if (carry > 0) {
            ans[i] += carry;
        }
    }

    string multiply(string num1, string num2) {
        n1 = num1.size();
        n2 = num2.size();
        vector<int> vec1(n1, 0);
        vector<int> vec2(n2, 0);

        for (int i = 0; i < n1; i++) {
            vec1[i] = num1[i] - '0';
        }
        for (int i = 0; i < n2; i++) {
            vec2[i] = num2[i] - '0';
        }

        int j = 0;
        for (int i = n2 - 1; i >= 0; i--) {
            f(vec1, num2[i], j);
            j++;
        }

        int idx = 0;
        while (idx < 10000 && ans[idx] == 0) { // Skip leading zeros
            idx++;
        }

        if (idx == 10000) return "0"; // If all digits are 0, return "0"

        string a = "";
        for (int i = idx; i < 10000; i++) {
            a += (ans[i] + '0'); // Convert digits back to characters
        }

        return a;
    }
};

24109