top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Multiply Strings - InterviewBit Solution

Problem Description:

Given two numbers represented as strings, return multiplication of the numbers as a string.

Note: The numbers can be arbitrarily large and are non-negative. Note2: Your answer should not have leading zeroes. For example, 00 is not a valid answer.

For example,

Given strings "12", "10", your answer should be “120”.

NOTE: DO NOT USE BIG INTEGER LIBRARIES ( WHICH ARE AVAILABLE IN JAVA / PYTHON ). We will retroactively disqualify such submissions and the submissions will incur penalties.

Solution Approach:

Doing it without using Big Integer Libraries is quite tiresome, but anyways let's do it:)

The approach to solve this is the same as how we solve it on paper. But since it is a program, we can write it more elegantly, as we know we have to add the multiplication in the end, so instead of doing it in end, we can keep doing that addition while multiplying as well. Since this will be done by the processor so we don't have to worry about the complexity of operations/calculations, we just have to worry about the complexity of the Algorithm :D

Time Complexity: O(N*M)

Where N is the length of string A, and M is the length of string B.

Space Complexity O(N+M)


Code in C++


bottom of page