Skip to content
HardLinked ListsAI interview only

Multiply Two Linked List Numbers

Asked atamazonmicrosoftgoogleadobe

01 · Problem

Two non-negative integers are stored in singly linked lists list1 and list2, one decimal digit per node, with the most significant digit first. The numbers can be far too large to fit in any built-in integer type, so you must not convert them to native integers.

Return the product as a new linked list of digits in the same most-significant-first format. The result must have no leading zeros; if the product is zero, return the single-node list [0].

02 · Examples

Example 01
Input
list1 = [1,2], list2 = [3]
Output
[3,6]

12 * 3 = 36.

Example 02
Input
list1 = [9,9], list2 = [9,9]
Output
[9,8,0,1]

99 * 99 = 9801.

Example 03
Input
list1 = [0], list2 = [4,5]
Output
[0]

Anything multiplied by zero is zero, returned as a single 0 digit.

03 · Constraints

  • 01The number of nodes in each list is in the range [1, 200].
  • 020 <= Node.val <= 9
  • 03Neither input has leading zeros, except the number 0 itself, which is represented as [0].
  • 04Do not convert the whole lists to built-in integer or big-integer types.

04 · Optimal complexity

Time
O(n * m)
Space
O(n + m)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.