DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
LinkedList

Add Two Numbers

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Add Two Numbers** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Digit-by-digit addition with carry **Edge Cases to Consider:** - (1) Lists of different lengths - (2) Carry propagates to new node - (3) Both lists are [0]

Examples

Example 1
Input: [2,4,3], [5,6,4]
Output: [7,0,8]
Explanation: 342+465=807
Example 2
Input: [0], [0]
Output: [0]
Explanation: 0+0=0
Example 3
Input: [9,9,9,9,9,9,9], [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]
Explanation: 9999999+9999=10009998

Constraints

  • ▪The number of nodes in the list is in the range [0, 500]
  • ▪-100 <= Node.val <= 100
  • ▪Solve in-place without copying node structures

Watch Out For Edge Cases

  • ▪Lists of different lengths
  • ▪Carry propagates to new node
  • ▪Both lists are [0]
Frequently Asked At
AmazonGoogleMicrosoftMetaAdobeFlipkart