Multiply Two Non-Negative Integers Given as Strings Without Integer Conversion

Quick Overview

Multiply two non-negative integers given as decimal strings of up to 200 digits and return the product as a string, without big-integer libraries or direct conversion. It tests grade-school multiplication, mapping each digit product to the right output position, carry handling, and removing leading zeros.

Multiply Two Non-Negative Integers Given as Strings Without Integer Conversion

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given two non-negative integers `num1` and `num2` represented as strings, return the product of `num1` and `num2`, also represented as a string. You must not use any built-in `BigInteger` library or convert the inputs to integers directly. ### Function Signature ```python def multiply_strings(num1: str, num2: str) -> str: ``` ### Rules - Converting a single digit character to its value is allowed. Converting a whole input string with `int()` or a similar call, or using any big-integer library, is not. In Python this rules out `int(num1) * int(num2)`. - Return the product in base 10 with no leading zeros. A product of zero is returned as `"0"`. ### Constraints - `1 <= len(num1), len(num2) <= 200` - `num1` and `num2` consist of digits only. - Neither input has leading zeros, except for the number zero itself, which is written `"0"`. ### Examples ```text Input: num1 = "123", num2 = "456" Output: "56088" ``` Splitting 456 into 400 + 56 gives 123 × 400 = 49200 and 123 × 56 = 6888, which sum to 56088. ```text Input: num1 = "999", num2 = "999" Output: "998001" ``` $(1000 - 1)^2 = 1000000 - 2000 + 1 = 998001$. Two 3-digit numbers can have at most a 6-digit product, and this one reaches that length. ```text Input: num1 = "0", num2 = "52" Output: "0" ``` Any product with zero is zero, and the answer is the single digit `"0"`, with no padding such as `"00"`.

Overview: Multiply two non-negative integers given as decimal strings of up to 200 digits and return the product as a string, without big-integer libraries or direct conversion. It tests grade-school multiplication, mapping each digit product to the right output position, carry handling, and removing leading zeros.

Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. You must not use any built-in BigInteger library or convert the inputs to integers directly.

Function Signature

def multiply_strings(num1: str, num2: str) -> str:

Rules

  • Converting a single digit character to its value is allowed. Converting a whole input string with int() or a similar call, or using any big-integer library, is not. In Python this rules out int(num1) * int(num2) .
  • Return the product in base 10 with no leading zeros. A product of zero is returned as "0" .

Constraints

  • 1 <= len(num1), len(num2) <= 200
  • num1 and num2 consist of digits only.
  • Neither input has leading zeros, except for the number zero itself, which is written "0" .

Examples

Input: num1 = "123", num2 = "456"
Output: "56088"

Splitting 456 into 400 + 56 gives 123 × 400 = 49200 and 123 × 56 = 6888, which sum to 56088.

Input: num1 = "999", num2 = "999"
Output: "998001"

(1000−1)2=1000000−2000+1=998001(1000 - 1)^2 = 1000000 - 2000 + 1 = 998001. Two 3-digit numbers can have at most a 6-digit product, and this one reaches that length.

Input: num1 = "0", num2 = "52"
Output: "0"

Any product with zero is zero, and the answer is the single digit "0", with no padding such as "00".