Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. You must not use any built-in BigInteger library or convert the inputs to integer directly.
Constraints: 1 ≤ num1.length, num2.length ≤ 200 · num1 and num2 consist of digits only · neither has leading zeros except the number 0 itself
Why strings? Because numbers like "123456789012345678901234567890" overflow every fixed-width integer type. Python's arbitrary-precision integers handle this silently, but Java, C++, and TypeScript all cap out at 64 bits — roughly 18 digits. When the constraint says “up to 200 digits,” you cannot convert to number at all.
The fix is the same algorithm you learned in third grade: grade-school long multiplication, digit by digit. The twist is that on paper, you use spatial alignment to track where each partial product goes. In code, you need a formula. Let's rediscover that formula by actually doing the multiplication — not watching it, but constructing it yourself.
| × | 1i=0 | 2i=1 | 3i=2 |
|---|---|---|---|
| 4j=0 | 1×4 | 2×4 | 3×4 |
| 5j=1 | 1×5 | 2×5 | 3×5 |
| 6j=2 | 1×6 | 2×6 | 3×6 |
Multiply "123" × "456" by computing digit pairs yourself. For each cell, you'll compute the product and then place it in the result array.