LC 43 — Problem

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.

Input: num1 = “123”, num2 = “456”
Output: “56088”
Input: num1 = "2“, num2 = ”3"
Output: "6"

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.

FIG. 1 — PARTIAL PRODUCTS · 0/9
×1i=02i=13i=2
4j=01×42×43×4
5j=11×52×53×5
6j=21×62×63×6
FIG. 2 — RESULT ARRAY · LENGTH 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.