Show problems as
Classic problem #43MediumMathStringSimulation

Multiply Strings

Real-world version: Punched Reel Product
Tracked in this browser only
Read Multiply Strings on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A stock-take terminal reads tallies off punched paper reels. A reel is written as a run of digit characters, heaviest digit first, and a reel can hold far more digits than any number type on the terminal can carry.

You are handed the reels left_reel and right_reel. Punch and return the reel that records their product. The digits are all you get to work with: feeding either reel into a built-in numeric type, or handing the job to a big-number library, is not allowed.

A reel never starts with a padding zero, the one exception being the single-digit reel "0", which stands for an empty tally. Your answer must obey the same rule.

Examples

Example 1

Input
left_reel = "47", right_reel = "206"
Output
"9682"

Column by column, 47 punched 206 times over lands on 9682, and no padding zero is needed in front.

Example 2

Input
left_reel = "70", right_reel = "30"
Output
"2100"

70 punched 30 times over lands on 2100. The trailing zero of each reel carries through to the answer, and no padding zero is written in front of it.

Example 3

Input
left_reel = "0", right_reel = "5814"
Output
"0"

An empty tally on one reel empties the product, and the answer is punched as the single digit 0 rather than a run of zeros.

Constraints

  • 1 <= left_reel.length, right_reel.length <= 200
  • left_reel and right_reel hold digit characters only
  • Neither reel starts with a zero unless the reel is exactly "0"

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def reel_product(left_reel: str, right_reel: str) -> str:
Java
public String reelProduct(String leftReel, String rightReel)