[1, 1, 0, 1] = -8 + 4 + 0 + 1 = -3.
You are given two numbers first and second in this notation, as digit arrays from the most significant position to the least. Return their sum in the same notation.
There are no leading zeros in the input or in the answer: an array is either [0] or starts with 1.first=[1, 1, 0], second=[1] → [1, 1, 1]
[1, 1, 0] is 4 - 2 + 0 = 2 and [1] is 1. Their sum 3 is written in base -2 as 4 - 2 + 1, that is [1, 1, 1].
first=[1, 1], second=[1] → [0]
[1, 1] is -2 + 1 = -1, and adding 1 gives 0, which is written as the single digit [0].
first=[1], second=[1] → [1, 1, 0]
1 + 1 = 2 = 4 - 2, so [1, 1, 0]: adding two ones already makes the result two digits longer.
first=[1, 1, 0], second=[1]
[1, 1, 1]
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.