Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sum Without Arithmetic Operators

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Sum Without Arithmetic Operators. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Intel oneAPI tooling may need a low-level integer routine that demonstrates how processor arithmetic can be modeled with logic operations. Implement a function that computes the sum of two signed 32-bit integers without using the +, -, *, or / operators anywhere in the function.

Formal Specification

Given integers a and b, return their sum using two's-complement 32-bit semantics. If the mathematical result overflows the signed 32-bit range, return the wrapped signed 32-bit value.

You may use bitwise operators, assignment, comparisons, loops, conditionals, and constants. Do not convert the numbers to strings or call arithmetic helpers that perform the addition internally.

Constraints

  • -2^31 <= a, b <= 2^31 - 1
  • The operators +, -, *, and / must not appear in the implementation.
  • Use signed 32-bit two's-complement semantics.
  • Use O(1) auxiliary space.

Function Signature

def add_without_operators(a, b):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output