Blind 75
75 / 75Free practice

Sum of Two Integers

Medium · Bit manipulation

Jump to code

Compute the sum of two signed 32-bit integers without using addition or subtraction operators. Use 32-bit two’s-complement wraparound if overflow occurs.

Examples

Example 1

a = 1
b = 2

Output: 3

Example 2

a = 2
b = 3

Output: 5

Constraints

  • -1000 <= a, b <= 1000
Need a hint?

XOR adds without carry; AND identifies the carry positions.

Real bit manipulation interview questions

Questions on the same topic that candidates reported from real company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 8 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  1,
  2
]
Expected
3
Case 2
Input
[
  2,
  3
]
Expected
5
Case 3
Input
[
  -1,
  1
]
Expected
0
Case 4
Input
[
  -5,
  -7
]
Expected
-12
Case 5
Input
[
  1000,
  -1000
]
Expected
0

Drafts are saved per language in this browser when storage is available.