![]() |
VOOZH | about |
Given two numbers as strings. The numbers may be very large (may not fit in long long int), the task is to find sum of these two numbers.
Examples:
Input: s1 = "23", s2 = "25"
Output: "48"Input: s1 = "00", s2 = "000"
Output: "0"Input: s1 = "10000000", s2 = "89990000"
Output: 99990000
The idea is to add two large numbers represented as strings by simulating the manual addition process. We traverse the strings from the end, adding corresponding digits along with a carry, building the result digit by digit.
Step by step approach:
48
Time Complexity: O(n + m), as both strings are traversed only once
Space Complexity: O(max(n, m)), to store the resultant string.