Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

76. Add Two Numbers

MediumDay 23 of 60Linked List

You get two non-empty linked lists l1 and l2. Each one stores a non-negative integer with its digits in reverse order, one digit per node (the head holds the ones digit). Return the sum of the two numbers as a linked list in the same reversed format. Neither number has leading zeros, except the number 0 itself.

Example 1
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
342 + 465 = 807, stored in reverse as 7, 0, 8.
Example 2
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]
Constraints
  • 1 <= number of nodes in each list <= 100
  • 0 <= Node.val <= 9
  • No leading zeros except the number 0
Hints
Frequently asked at: Amazon, Microsoft, Bloomberg, Adobe, Apple
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min