![]() |
VOOZH | about |
Given an array arr[] consisting of N integers, and an integer K, the task is to find the maximum number of inversions of the given array possible after the removal of K array elements.
Examples:
Input: arr[] = {2, 3, 4, 1}, K = 2
Output: 1
Explanation: Removing the 1st and 2nd array elements modifies the array to {4, 1}. Therefore, the maximum number of inversions is 1.Input: arr[] = {4, 3, 2, 1}, K = 3
Output: 0
Explanation: Since the array after K removals will have only 1 element remaining, the maximum number of inversions is 0.
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
1
Time Complexity: O((N!)*(N - K)2)
Auxiliary Space: O(N)