


In cases where the dividend is not perfectly divisible by the divisor, you are required to return the integer value of the quotient which is closer to zero.
For example - If the answer is '8.34', we return the integer part, i.e., '8'. Also, If the answer is '-2.67', we return the integer part, i.e., '-2'.
Assume we're dealing with a system that can only store integers in the 32-bit signed integer range: [2^31, 2^31-1]. If the quotient is higher than 2^31 - 1, return 2^31 - 1; if it is less than -2^31, return -2^31.
If the answer is ‘9.333’, then return ‘9’, or if the answer is ‘-8.123’, then return ‘-8’.
The first input line contains two space-separated integers, ‘dividend’ and ‘divisor’.
The only line contains the result after division, following the above rules.
You do not need to print anything. It has already been taken care of. Just implement the given function.
We can subtract the divisor from the dividend until the dividend is greater than the divisor. The quotient will be equal to the number of total subtractions performed.
In this case quotient is = ‘2^3 + 2^2 +2^0 =13 = floor(107/8)’.
The intuition here is that we can find the largest power of 2’s which can satisfy the equation ‘dividend = divisor * maximum 2’s power + remainder’.
If found we set ‘quotient’ to ‘quotient = quotient + maximum 2’s power’.
Below is the detailed algorithm: