Coding Interview PatternsSum of Two Integers
MediumBitwise Manipulation

Sum of Two Integers

Explanation & Solution

Description

Given two integers a and b, return the sum of the two integers without using the operators `+` and `-`.

Input: a = 1, b = 2

Output: 3

Constraints

  • -1000 <= a, b <= 1000

Approach

Bitwise Manipulation pattern

Key Insight

  • This simulates how a hardware adder works at the gate level
  • Time: O(1) for bounded integers | Space: O(1)

Solution Code