711. Multiply Two Numbers Without * Operator

EasyRecursionRecursion

Given two integers a and b, return their product a * b without using the multiplication operator. Use recursion (and addition/subtraction) only. Your function must correctly handle negative numbers and zero.

Input: Two integers a and b separated by a comma.

Output: Return an integer equal to a * b.

Examples

Example 1
Input: 3, 4
Output: 12
Explanation: Add 3 four times: 3+3+3+3 = 12.
Example 2
Input: -5, 6
Output: -30
Explanation: Result is negative because exactly one operand is negative.
Example 3
Input: 0, 100
Output: 0
Explanation: Anything times zero is zero.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →