Tap here to switch tabs
Problem
Ask
Submissions

Problem: Adding Two Negabinary Numbers

med
30 min
Understand how to add two numbers in negabinary form, where values are expressed in base -2, using arrays of bits. Learn to handle the unique carry rules and return results without leading zeros, applying mathematical reasoning to solve this coding challenge.

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:

  • 11 \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
Ask
Submissions

Problem: Adding Two Negabinary Numbers

med
30 min
Understand how to add two numbers in negabinary form, where values are expressed in base -2, using arrays of bits. Learn to handle the unique carry rules and return results without leading zeros, applying mathematical reasoning to solve this coding challenge.

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:

  • 11 \leq arr1.length, arr2.length 1000\leq 1000

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

  • arr1 and arr2 have no leading zeros