Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 2.01 KB

File metadata and controls

30 lines (22 loc) · 2.01 KB

Sum of Two Integers medium #javascript #blind75 #bit-manipulation

by Pawan Kumar @jsartisan

Take the Challenge

Given two integers a and b, calculate their sum without using the + or - operators.

Rules:

  • Cannot use addition (+) operator
  • Cannot use subtraction (-) operator
  • Must handle both positive and negative numbers
  • Must return correct sum

Constraints:

  • -1000 ≤ a, b ≤ 1000

Examples:

// Example 1:
console.log(getSum(1, 1));
// Output: 2
// Explanation: 1 + 1 = 2

// Example 2:
console.log(getSum(4, 7));
// Output: 11
// Explanation: 4 + 7 = 11

Note: You'll need to use bitwise operations to solve this problem.


Back Share your Solutions Check out Solutions