![]() |
VOOZH | about |
Given two numbers, n and r, the task is to compute nPr, which represents the number of ways to arrange r elements from a set of n elements. It is calculated using the formula n!/(nār)!, where "!" denotes the factorial operation.
š Permutation - Formula, Definition ...Examples:
Input: n = 5
r = 2
Output: 20
Explanation:5P2 = 5! / (5 - 2)! = 20
Input: n = 6
r = 3
Output: 120
Explanation:6P3 = 6! / (6 - 3)! = 12
For calculating nPr using an iterative factorial function. First computes n! and (n - r)! separately and then divides them to get the result. The factorial function uses a loop to multiply numbers from 1 to n.
5P2 = 20