CodeSpeek

Multiply Strings

Medium · Math & Geometry

You are given two non-negative integers, each represented as a string of digits with no leading zeros (unless the value is exactly zero). Compute their product and return it as a string, again with no leading zeros. Treat this as a digit-by-digit arithmetic exercise rather than converting the whole strings straight into a built-in big integer type. The inputs can be very long, longer than what fits in a normal fixed-size integer in many languages.

Examples

Input:  num1 = "2", num2 = "3"
Output: "6"
Why:    2 times 3 equals 6.
Input:  num1 = "123", num2 = "456"
Output: "56088"
Why:    123 times 456 equals 56088.
Input:  num1 = "0", num2 = "52"
Output: "0"
Why:    Anything multiplied by zero is zero.

Constraints

1 <= num1.length, num2.length <= 200, both strings contain only digits 0-9 and have no leading zeros unless the number itself is "0"

Practise it by voice

Describe the solution out loud and the interviewer writes exactly what you say, asks when you are vague, and runs the tests in your browser.

Practise Multiply Strings

This statement is written for CodeSpeek. The problem is part of the NeetCode 150 list; Watch NeetCode's explanation of Multiply Strings. Reference solutions from the NeetCode repository (MIT) are used to verify our tests.