Divide Two Integers

Given two integers dividend and divisor, divide them without using multiplication, division, or mod operator and return the quotient truncated toward zero. Clamp the result to the 32-bit signed integer range if overflow occurs.

Input Format

dividend and divisor = integers

Output Format

truncated quotient as a 32-bit signed integer

Constraints

  • dividend and divisor are 32-bit signed integers; divisor != 0

Examples

Example 1:

Input:

dividend = 10
divisor = 3

Output:

3

Explanation:

10 / 3 truncates toward zero as 3.

Example 2:

Input:

dividend = 7
divisor = -3

Output:

-2

Explanation:

7 / -3 = -2.333..., truncated toward zero is -2.

Loading...
Divide Two Integers - Math DSA Problem