X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Division without using multiplication, division and mod operator
Medium Accuracy: 62.1% Submissions: 7583 Points: 4

Given two integers dividend and divisor. Find the quotient after dividing dividend by divisor without using multiplication, division and mod operator.

Example 1:

Input:
a = 10, b= 3
Output: 3
Exaplanation:
10/3 gives quotient as 3
and remainder as 1.

Example 2:

Input:
a = 43, b = -8
Output: -5
Explanation:
43/-8 gives quotient as -5 and
remainder as 3.
You don't have to read input or print anything. Your task is to complete the function divide() which takes two integers a and b as input and returns the quotient after dividing a by b.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints :
-10^9 <= a,b <= 10^9