Problem
Ask
Submissions

Problem: Adding Two Negabinary Numbers

Medium
30 min
Explore how to add two numbers in negabinary format by working with arrays representing base negative two values. Understand the problem constraints and practice implementing a solution without leading zeros to solidify your math and coding interview skills.

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

Problem
Ask
Submissions

Problem: Adding Two Negabinary Numbers

Medium
30 min
Explore how to add two numbers in negabinary format by working with arrays representing base negative two values. Understand the problem constraints and practice implementing a solution without leading zeros to solidify your math and coding interview skills.

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