
At Stripe, you need to implement integer division for a low-level utility where the / and * operators are not allowed. Given two integers dividend and divisor, return the quotient after dividing dividend by divisor.
Truncate toward zero, as in most programming languages. You may not use multiplication, division, or modulus operators.
dividend and divisordividend / divisor, truncated toward zero2147483647Example 1
dividend = 10, divisor = 3310 / 3 = 3.333..., so truncating toward zero gives 3.Example 2
dividend = 7, divisor = -3-27 / -3 = -2.333..., so truncating toward zero gives -2.-2^31 <= dividend <= 2^31 - 1-2^31 <= divisor <= 2^31 - 1divisor != 0O(log |dividend|) time or betterdividend = 10, divisor = 3Output3WhyThe integer quotient is `3` because `10 / 3` truncates toward zero.dividend = 7, divisor = -3Output-2WhyThe exact value is `-2.333...`, and truncation toward zero gives `-2`.dividend = -2147483648, divisor = -1Output2147483647WhyThe mathematical result exceeds 32-bit signed integer range, so the value is clamped to `2147483647`.-2^31 <= dividend <= 2^31 - 1-2^31 <= divisor <= 2^31 - 1divisor != 0Do not use multiplication, division, or modulus operatorsTarget time complexity is O(log |dividend|) or betterdef divide_integers(dividend, divisor):