Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Integer Division Without Operators

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

Your question is Integer Division Without 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

At Stripe, you need to implement integer division for a low-level utility where the / and * operators are not allowed. Given two integers dividend and divisor, return the quotient after dividing dividend by divisor.

Truncate toward zero, as in most programming languages. You may not use multiplication, division, or modulus operators.

Formal Specification

  • Input: Two integers, dividend and divisor
  • Output: An integer quotient equal to dividend / divisor, truncated toward zero
  • If the result overflows 32-bit signed integer range, return 2147483647

Constraints

  • -2^31 <= dividend <= 2^31 - 1
  • -2^31 <= divisor <= 2^31 - 1
  • divisor != 0
  • Do not use multiplication, division, or modulus operators
  • Target time complexity is O(log |dividend|) or better

Function Signature

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