28. Multiply Strings

28. Multiply Strings

Medium
41.0%
1.5k
stringmath
Target time complexity is O(n × m), where n and m are the lengths of the input strings.

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large-scale financial or analytics platform processes extremely large numeric values represented as strings. These values may exceed the limits of built-in integer types due to high precision requirements, regulatory constraints, or cross-system compatibility.

Because of this, the platform cannot directly convert these strings into numeric data types. Instead, it needs a safe and accurate way to multiply two non-negative numbers that are provided as strings and return the result as a string.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given two non-negative integers num1 and num2 represented as strings, return their product, also represented as a string.

You must not use any built-in big integer libraries or convert the input strings directly into integers.

Input Format

  • num1: a string representing a non-negative integer
  • num2: a string representing a non-negative integer

Output Format

  • A string representing the product of num1 and num2

Examples

Example 1:

Input: num1 = "2" num2 = "3"
Output: "6"

Example 2:

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

Example 3:

Input: num1 = "0" num2 = "12345"
Output: "0"

Constraints

  • 1 <= num1.length, num2.length <= 200
  • num1 and num2 consist of digits only
  • num1 and num2 do not contain leading zeros except the number "0"

Loading editor...

"2", "3"
"6"

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback