codejump
MediumPro challengePythonJavaScriptTypeScript

Math — Multiply Strings

AlgorithmsMathStrings

solve(num1, num2) — num1 and num2 are non-negative integers written as strings
(no leading zeros except for "0" itself). Return their product, also as a string. The
numbers can have hundreds of digits, so you may not convert them to integers or use
BigInt — multiply digit by digit like on paper.

Digit i of num1 (from the right) times digit j of num2 lands in position
i + j of the result, with its carry going to i + j + 1. Accumulate everything in an array of
len1 + len2 digits, then strip leading zeros.

Examples

solve("2", "3")        → "6"
solve("123", "456")    → "56088"
solve("999", "999")    → "998001"
solve("0", "9133")     → "0"

Sample tests

Test #1Single digits
Input: ["2","3"]
Output: "6"
Test #2Three digits
Input: ["123","456"]
Output: "56088"
Test #3Zero
Input: ["0","9133"]
Output: "0"