Sum of Two Integers
Given two integers a and b Return the sum of a and b without using + or - operators Example: a = 1, b = 2 => 3 Example: a = 2, b = 3 => 5
This is a math-leaning question that rewards careful reasoning over trial-and-error. Interviewers love it because it reveals your turning constraints into math and your edge-case discipline. Watch for overflow, signs, and off-by-one edges—those are what interviews probe.
Examples
You write
get_sum(a: int, b: int)
Example 1
- Input
- a = 1, b = 2
- returns
- 3
Example 2
- Input
- a = 2, b = 3
- returns
- 5
The pattern behind it
Bit Manipulation
I reach for it when
- The statement bans extra space or restricts operators.
- Numbers act as flags, masks or XOR pairs.
Say this before you type. Say what each bit means in this problem before you shift or mask anything.
All 12 Bit Manipulation problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.