Add Two Numbers

Medium

Problem Description

Add Two Numbers

Problem Statement

Given two non-negative integers represented as linked lists, where each node in the lists contains a digit representing a number from 0 to 9, find the result of adding the two numbers represented by these linked lists.

Rules and Constraints

  • The input numbers are represented as linked lists in reverse order (i.e., the least significant digit is the head of the list).
  • Each node in the input linked lists contains a single digit (a number from 0 to 9).
  • The sum of the two input numbers will not exceed the maximum limit of the data type for the output.
  • Output the result of adding the two numbers represented by the linked lists as a linked list in reverse order.
  • Time complexity: O(max(m, n)), where m and n are the lengths of the input linked lists.
  • Space complexity: O(max(m, n)), where m and n are the lengths of the input linked lists.

Example

Input: {"l1":[2,4,3],"l2":[5,6,4]} Output: [7,0,8]

CompaniesGoogleAmazonMeta
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.