Back to Practice Dashboard
Top 150 InterviewEasy

Multiply Strings

Learn how to solve the 'Multiply Strings' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

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

Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.

Implement a function multiply(num1: str, num2: str) -> str.

Constraints
  • 1 <= num1.length, num2.length <= 200
  • num1 and num2 consist of digits only
  • Both num1 and num2 do not contain any leading zero, except the number 0 itself

Examples

Example 1
Input
"2", "3"
Output
"6"
Explanation

2 * 3 = 6.

Example 2
Input
"123", "456"
Output
"56088"
Explanation

123 * 456 = 56088.

Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor