Skip to main content
Back to problems
Leetcode
Medium
Math
Bit Manipulation
Divide and Conquer
Google
Amazon
Microsoft
Divide Two Integers

Compute the quotient of two integers without using multiplication, division, or modulo operators.

Acceptance 0%
Problem Statement

Given two signed 32-bit integers dividend and divisor, compute the integer quotient of dividend divided by divisor without using multiplication, division, or modulo operators.

Truncate the result toward zero, just like integer division in most programming languages.

Because the exact mathematical quotient may exceed the 32-bit signed integer range, clamp the final answer to the range [231,2311][-2^{31}, 2^{31}-1] when necessary.

Input Format

  • One integer dividend
  • One integer divisor

Both values fit in 32-bit signed integer range.

Output Format

  • Return the truncated integer quotient dividend / divisor, clamped to 32-bit signed integer range if overflow occurs.

Constraints

  • 231dividend,divisor2311-2^{31} \le dividend, divisor \le 2^{31} - 1
  • divisor != 0
  • Do not use multiplication, division, or modulo operators
  • Truncate toward zero
  • Final answer must fit in signed 32-bit integer range
Examples
Sample cases returned by the problem API.

Example 1

Input

dividend = 10, divisor = 3

Output

3

Explanation

10 / 3 = 3.333..., and truncating toward zero gives 3.

Example 2

Input

dividend = 7, divisor = -3

Output

-2

Explanation

7 / -3 = -2.333..., and truncating toward zero gives -2.

Show 1 more example

Example 3

Input

dividend = -2147483648, divisor = -1

Output

2147483647

Explanation

The mathematical result is 2147483648, which overflows 32-bit signed integer range, so the answer is clamped to 2147483647.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.