Tap here to switch tabs
Problem
Submissions

Problem: Adding Two Negabinary Numbers

Adding Two Negabinary Numbers gives you two arrays of bits representing values in base negative two. Compute their sum and return it as a negabinary array without leading zeros.

Statement

You are given two numbers represented in negabinary (base −2-2). Each number is provided as an array of 00s and 11s, ordered from the most significant bit to the least significant bit. For instance, arr = [1,1,0,1] corresponds to the value (−2)3+(−2)2+(−2)0=−3(-2)^3 + (-2)^2 + (-2)^0 = -3.

Each input array is guaranteed to contain no leading zeros: either the array is [0], or the first element is 11.

Given two such arrays arr1 and arr2, compute their sum and return the result in the same negabinary array format, with no leading zeros.

Constraints:

  • 1≤1 \leq arr1.length, arr2.length ≤1000\leq 1000

  • arr1[i] and arr2[i] are 00 or 11

  • arr1 and arr2 have no leading zeros

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Adding Two Negabinary Numbers

Adding Two Negabinary Numbers gives you two arrays of bits representing values in base negative two. Compute their sum and return it as a negabinary array without leading zeros.

Statement

You are given two numbers represented in negabinary (base −2-2). Each number is provided as an array of 00s and 11s, ordered from the most significant bit to the least significant bit. For instance, arr = [1,1,0,1] corresponds to the value (−2)3+(−2)2+(−2)0=−3(-2)^3 + (-2)^2 + (-2)^0 = -3.

Each input array is guaranteed to contain no leading zeros: either the array is [0], or the first element is 11.

Given two such arrays arr1 and arr2, compute their sum and return the result in the same negabinary array format, with no leading zeros.

Constraints:

  • 1≤1 \leq arr1.length, arr2.length ≤1000\leq 1000

  • arr1[i] and arr2[i] are 00 or 11

  • arr1 and arr2 have no leading zeros