shlogg · Early preview
Rakesh Reddy Peddamallu @rakesh678219

Carry In Linked List Addition: Handling Sums Exceeding 9

Add two numbers represented as linked lists. Handle carry when sum > 9. Time complexity: O(max(N, M)), space complexity: O(max(N, M)).

Understanding Carry in Linked List Addition

  
  
  Key Concepts

Numbers are stored in reverse order as linked lists.
Each node contains a single digit.
Carry is needed when sum > 9.
Result is returned as a new linked list.

  
  
  Approach

Initialize a dummy node to simplify list construction.
Use a carry variable to handle sums exceeding 9.
Traverse l1 and l2, summing corresponding nodes.
If one list is shorter, treat missing nodes as 0.
Continue processing even if one list is exhausted.
Add a new node if there’s a leftover carry.

  
  
  Complexity Analysis


Time Complexity: O(max(N,...