Add two integers without using the plus or minus operators

Quick Overview

Compute the sum of two signed integers without the plus or minus operators. It tests bitwise reasoning about carries, two's complement representation, and how fixed-width overflow has to be simulated in a language whose integers have no fixed size.

Add two integers without using the plus or minus operators

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

Given two integers `a` and `b`, calculate their sum without using the `+` or `-` operators. ### Function Signature ```python def get_sum(a: int, b: int) -> int: ``` ### Rules - The `+` and `-` operators may not appear anywhere in the function, including `+=`, `-=` and unary minus. - Return the sum as an ordinary signed Python `int`, so a negative sum is returned as a negative number. ### Constraints - `-10^5 <= a, b <= 10^5` ### Examples ```text Input: a = 3, b = 5 Output: 8 ``` Both inputs are positive and their sum is 8. ```text Input: a = -4, b = 10 Output: 6 ``` The signs are mixed: adding 10 to -4 gives 6. ```text Input: a = -7, b = -8 Output: -15 ``` Both inputs are negative, so the expected output is the negative integer -15.

Overview: Compute the sum of two signed integers without the plus or minus operators. It tests bitwise reasoning about carries, two's complement representation, and how fixed-width overflow has to be simulated in a language whose integers have no fixed size.

Nov 25, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Given two integers a and b, calculate their sum without using the + or - operators.

Function Signature

def get_sum(a: int, b: int) -> int:

Rules

  • The + and - operators may not appear anywhere in the function, including += , -= and unary minus.
  • Return the sum as an ordinary signed Python int , so a negative sum is returned as a negative number.

Constraints

  • -10^5 <= a, b <= 10^5

Examples

Input: a = 3, b = 5
Output: 8

Both inputs are positive and their sum is 8.

Input: a = -4, b = 10
Output: 6

The signs are mixed: adding 10 to -4 gives 6.

Input: a = -7, b = -8
Output: -15

Both inputs are negative, so the expected output is the negative integer -15.