![]() |
VOOZH | about |
Given an array, arr[] consisting of N distinct elements, the task is to count possible permutations of the given array that can be generated which satisfies the following properties:
Note: N is always even and indexing starts from 0.
Examples:
Input: arr[] = {10, 20, 30, 40}
Output: 2
Explanation:
Possible permutations of the given array that satisfy the given conditions are:{{10, 20, 30, 40}, {10, 30, 20, 40}}.
Therefore, the required output is 2.Input: arr[] = {1, 2}
Output: 1
Approach: Follow the steps below to solve the problem:
= [{N × (N - 1) × ............. × (N - R + 1)} / {(R × (R - 1) × ..... × 1)}]
Below is the implementation of the above approach:
2
Time Complexity: O(N)
Auxiliary Space: O(1)