Ctrl K

Adding Without a Plus

Medium
You are given two integers x and y. Return their sum without using the + and - operators anywhere in your code (+= and -= included). Hint: think about column addition in binary: what a single bit position gives you without the carry, and where the carry itself comes from.
Example 1
x=7, y=6 → 13

A plain sum: 7 and 6 make 13, but you have to get there without + and -.

Example 2
x=-9, y=4 → -5

Numbers of opposite signs: -9 + 4 = -5.

Example 3
x=-250, y=-750 → -1000

Two negative numbers add up to -1000.

Constraints
  • -1000 ≤ x, y ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDivision Without Dividing MediumMirrored One-Bit Codes MediumShared Pool Race to a Goal MediumSum of Bit Differences MediumA Four-Button Lamp Panel Medium
loading Python…
Input
x=7, y=6
Expected
13

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.