Skip to content
DeepForgeby svx
All problems
HardAlgorithmsal-165

Multiply Strings

Problem

Multiply two non-negative integers given as decimal strings and return the product as a decimal string, without converting the inputs to integers.

The classic grade-school algorithm stores partial products in a digit array of length m + n: digit i + j + 1 receives the ones and i + j receives the carry. Strip leading zeros and return 0 when either input is 0.

Hint

The digit at position i + j + 1 is the ones place of a partial product, and i + j carries.

Test cases

case 1
in: ["2","3"]
expected: "6"
case 2
in: ["123","456"]
expected: "56088"
case 3
in: ["0","0"]
expected: "0"
case 4
in: ["999","999"]
expected: "998001"
case 5
in: ["12","0"]
expected: "0"
Starter codePython
def multiply_strings(num1, num2):
    # Your code here
    pass

5 test cases · run your code against them in the editor