← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Meta/Leetcode 371. Sum of Two Integers
CodingMust
Implement a function that calculates the sum of two integers without using the addition (+) or subtraction (-) operators. You must rely solely on bitwise operations to perform the calculation.
The challenge requires understanding how binary addition works at the bit level: computing the sum bits and the carry bits separately, then combining them iteratively until no carry remains.
+ or - operators anywhere in your solutionExample 1:
Input: a = 3, b = 2 Output: 5 Explanation: Binary addition without arithmetic operators: 011 + 010 = 101
Example 2:
Input: a = -2, b = 3 Output: 1 Explanation: Two's complement handles negative numbers correctly
Example 3:
Input: a = 0, b = 0 Output: 0 Explanation: Sum of zeros is zero