Compute the quotient of two integers without using multiplication, division, or modulo operators.
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 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
divisor != 0- Do not use multiplication, division, or modulo operators
- Truncate toward zero
- Final answer must fit in signed 32-bit integer range
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.