Add Numbers Stored in Four-Digit Chunks
Problem statement
Each array represents one nonnegative integer as base-10000 chunks in most-significant-first order. Every chunk is between 0 and 9999; conceptual leading zeroes inside a chunk are allowed.
Add the represented numbers and return normalized base-10000 chunks in the same order. Return [0] for zero and omit other leading zero chunks.
Function
addChunkedNumbers(first: int[], second: int[]) → int[]Examples
Example 1
first = [1,9999]second = [2]return = [2,1]9999 plus 2 produces a carry into the preceding chunk.
Example 2
first = [12,34]second = [5,6,7]return = [5,18,41]Missing high chunks are treated as zero.
Constraints
1 <= first.length, second.length <= 1000000 <= chunk < 10000