Day 3 - Linked Lists
Practice Questions
Multiply Two Numbers Represented as Linked Lists

Multiply Two Numbers Represented as Linked Lists

Description

  • Given two numbers represented by two linked lists, write a function that returns the multiplication of these two linked lists.

Constraints

  • 1 <= N, M <= 100 - Size of Linked Lists

Test Cases

  • Input: l1 = [9, 4, 6], l2 = [8, 5]
    Output: 79464

  • Input: l1 = [3, 2, 1], l2 = [1, 2]
    Output: 3852

Code

Approach 1: Iterative

Explanation

  1. Traverse both the linked lists and convert them into numbers.
  2. Multiply the numbers and return the result.

Analysis

  • Time Complexity: O(max(N, M))
  • Space Complexity: O(1)