Factorial of N II

Given a positive integer N, return the factorial of N using recursion.

The factorial of N is the product of all positive integers from 1 to N.

Note:

A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.

Example 1:

Input: N = 5

Output: 120

Explanation: 5! = 5 * 4 * 3 * 2 * 1 = 120.

Example 2:

Input: N = 1

Output: 1

Explanation: 1! = 1.

Now Your Turn!

Pick the correct output for the given input

Input: N = 4

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N <= 15

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
long long factorial(int N) {
// Your code goes here
}
};
Test Case

Input:

N