Problem 303293 · hard · Phase 03 Linear Management & Searching

Multiply Two Numbers Written as Text

strings · big numbers · carry propagation

An accounting tool receives amounts as decimal digit strings that may be far longer than any machine integer. Given two non-negative integers a and b written as strings (no sign, no leading zeros except the number "0" itself), return their product as a string. Do not convert the whole strings with int(); work digit by digit like on paper.

Examples

Input:  a = "123", b = "45"
Output: "5535"

Input:  a = "0", b = "999"
Output: "0"

Constraints

  • 1 <= len(a), len(b) <= 200
  • Target: O(len(a) * len(b)) time.

Goals

  • Store partial products in a digit array indexed by position
  • Propagate carries in a single pass after accumulating
  • Strip leading zeros without losing a lone zero
Starting Python…