Multiply Strings
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two non-negative integers, num1 and num2, each represented as a string of decimal digits. Return their product, also represented as a string.
The catch: you must compute the result **without** converting the inputs directly into a built-in big-integer type (and without using any library routine like BigInteger). Treat the numbers purely as sequences of digit characters and reproduce the long-multiplication procedure you would do by hand.
Both inputs consist only of the characters '0' through '9'. Neither string has a leading zero unless the value itself is exactly "0". Your returned string must follow the same rule: no leading zeros, and the product of any factor with "0" is "0".
The core idea is the **grade-school multiplication** algorithm. When the digit at index i of num1 is multiplied by the digit at index j of num2, that partial product contributes to positions i + j and i + j + 1 of a result buffer of length len(num1) + len(num2). Accumulating every digit-by-digit product into this buffer, then propagating carries, yields the final answer.
Examples
Constraints
- 1 <= num1.length, num2.length <= 200
- num1 and num2 consist of digits '0' through '9' only.
- Neither num1 nor num2 has a leading zero, except for the value "0" itself.
- You must not convert the inputs to a big-integer type or use library big-number multiplication.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.