InferenceAI

Enter at least two characters to search.

Start free

Multiply Digit Strings

mediumMath25 min25 XP

Given two non-negative integers as decimal strings, return their product as a string, without converting the whole inputs to integers.

Requirements

  • Use grade-school multiplication: digit ii of one number times digit jj of the other contributes to position i+ji + j.

Constraints

  • Each string has 1 to 200 digits and no leading zeros (except the number "0").

Examples

EXAMPLE WALKTHROUGHsingle digits

A guided view of the published example, not a trace of your code.

INPUT["2","3"]
TASKmultiply_digit_strings()
EXPECTED OUTPUT"6"

Start with the input values shown in this example.

Example 1 of 3

Input: a = "2", b = "3"

Output: "6"

Explanation: single digits

Input: a = "123", b = "456"

Output: "56088"

Explanation: three digits

Input: a = "0", b = "52"

Output: "0"

Explanation: zero

Hint 1

Allocate len(a) + len(b) slots for the result digits.

Hint 2

Accumulate products, then carry from right to left and strip leading zeros.

Topics

DSAMathPython