Description

Divide two integers without using multiplication, division, and mod operators. Return the integer quotient truncated toward zero.

Examples

Input:dividend = 10, divisor = 3
Output:3
Explanation:

10/3 = 3 truncated.

Input:dividend = 7, divisor = -3
Output:-2
Explanation:

Works with negative numbers.

Input:dividend = -2147483648, divisor = -1
Output:2147483647
Explanation:

This tests the integer overflow edge case. -2147483648 / -1 should equal 2147483648, but this exceeds the maximum 32-bit signed integer (2147483647), so the result is clamped to 2147483647.

Constraints

  • -2³¹ ≤ dividend, divisor ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!