737. Recursive Floor Division

EasyRecursionRecursion

Given two integers a and b (with b != 0), return the floor of a / b — the largest integer q such that q * b <= a (mathematical floor division, like Python's // operator). The result must be correct for negative operands as well: for example, floor(-7 / 2) = -4, not -3. Implement the division recursively without using language-built-in division operators on the final answer (use repeated subtraction or modular reasoning).

Input: Two integers a and b (with b != 0) separated by a comma.

Output: Return an integer equal to floor(a / b).

Examples

Example 1
Input: 10, 3
Output: 3
Explanation: 10/3 = 3.33..., floor is 3.
Example 2
Input: -7, 2
Output: -4
Explanation: -7/2 = -3.5, floor is -4.
Example 3
Input: 0, 5
Output: 0
Explanation: 0 divided by anything (non-zero) is 0.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →