DIY: Multiply Strings
Solve the interview question "Multiply Strings" in this lesson.
We'll cover the following
Problem statement
You are given two non-negative integers represented as strings. Your task is to find the product of the given two integer numbers in the form of a string. For this, you will first convert the given strings to an integer without using the built-in library and then use the multiplication operator.
Constraints
1 <= first_number.length, second_number.length <= 200
first_number
andsecond_number
consist of digits only.- The
first_number
and thesecond_number
do not contain any leading zero, except the number 0 itself.
Input
The inputs to the function are strings with integer values. The following is an example input:
first_number = 5
second_number = 6
Output
The following is the output of the above input:
30
Coding exercise
Implement the function multiply(first_number, second_number)
, which accepts two string arguments first_number
and second_number
storing non-negative integer numbers and returns the product of the two integers as a string.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.