MediumStringsAI interview only
Multiply Strings
Asked atmetagoogleamazonmicrosoftapplebloomberg
01 · Problem
You are given two non-negative integers num1 and num2 written as decimal strings. Return their product, also as a decimal string.
You must not convert the inputs directly to integers or use any built-in big-integer library — implement the multiplication on the digits yourself.
The result must not have leading zeros; if the product is zero, return "0".
02 · Examples
Example 01
Input
num1 = "12", num2 = "34"
Output
"408"
12 x 34 = 408.
Example 02
Input
num1 = "305", num2 = "27"
Output
"8235"
305 x 27 = 8235.
Example 03
Input
num1 = "0", num2 = "9876"
Output
"0"
Anything multiplied by zero is zero, returned as the single digit "0".
03 · Constraints
- 011 <= num1.length, num2.length <= 200
- 02num1 and num2 consist of digits only
- 03Neither num1 nor num2 has leading zeros, except the number 0 itself
04 · Optimal complexity
- Time
- O(m * n)
- Space
- O(m + n)
05 · Two ways to work on it
Practice it alone or rehearse it as an interview.
Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.