Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Divide Integers Without Division

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

Your question is Divide Integers Without Division. 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

The Fannie Mae Desktop Underwriter (DU) calculation layer needs integer division for bounded values, but the arithmetic primitive cannot use division, modulo, or multiplication operators. Implement a function that returns the quotient and remainder of two integers.

The quotient must truncate toward zero. The remainder must have the same sign as the dividend, satisfying dividend = divisor * quotient + remainder mathematically. You may use addition, subtraction, comparisons, bit shifts, bitwise operations, and unary negation. The divisor is guaranteed to be nonzero.

Formal Specification

Implement divide_integers(dividend, divisor).

  • Input: Two integers, dividend and divisor.
  • Output: A two-element list [quotient, remainder].
  • Do not use /, //, %, or multiplication in the implementation.
  • The result should support signed 32-bit input values and mathematical integer output.

Constraints

  • -2^31 <= dividend <= 2^31 - 1
  • -2^31 <= divisor <= 2^31 - 1
  • divisor != 0
  • Do not use /, //, %, or multiplication
  • Return mathematical integer results without fixed-width overflow

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