This question evaluates algorithmic skills in manipulating linked lists or arrays to perform addition of large integers, focusing on carry propagation, handling differing lengths, and analysis of time and space complexity.
You are given two non-empty singly linked lists (or arrays) representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit from 0 to 9.
Your task is to add the two numbers and return the sum as a new linked list, also in reverse order.
You may assume:
Input:
Output:
Input:
Output:
Task: Describe an algorithm to perform this addition and construct the resulting linked list in O(n + m) time and O(1) additional space (excluding the space for the output list).