FastPrepAdd Numbers Stored in Four-Digit Chunks

Add Numbers Stored in Four-Digit Chunks

ZipRecruiter logoZipRecruiter● MediumNEW GRADONSITE INTERVIEW
Learn

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 <= 100000
  • 0 <= chunk < 10000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] addChunkedNumbers(int[] first, int[] second) {
    // Write your code here.
}
first[1,9999]
second[2]
expected[2,1]
Checking account…