Skip to content
Decoder

Sum of Two Integers

Medium

Problem

Return the sum of the integers a and b without using the operators `+` or `-` (and without helpers like sum). Work with the bits directly.

Example 1

Input
a = 1, b = 2
Output
3

Example 2

Input
a = 2, b = 3
Output
5

Example 3

Input
a = -5, b = -7
Output
-12

Constraints

  • -1000 <= a, b <= 1000
  • Treat the numbers as signed 32-bit integers.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.