1065. Permutations in which N people can occupy R seats

You are given two integers N and R representing the number of people and the number of available seats respectively. Your task is to find the number of permutations in which these N people can occupy the R seats.

Please provide your answer with mod of (109 + 7).

Example 1:

Input: N = 5, R = 3

Output: 60

Explanation: P(5, 3) = 5! / (5 - 3)! = 120 / 2 = 60

Example 2:

Input: N = 6, R = 4

Output: 360

Explanation: P(6, 4) = 6! / (6 - 4)! = 720 / 2 = 360

Now Your Turn!

Pick the correct output for the given input

Input: N = 7, R = 7

Still unsure what the problem is asking ?

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

Constraints:

  • 1 ≤ R ≤ N ≤ 20
0
class Solution {
public:
long long permutations(int n, int r) {
// Your code goes here
}
};
 
Test Case

Input:

N
R