Company: UKG_20july
Difficulty: medium
Maximum Greatness Problem Description Given an array arr , we can rearrange it to form another array, let's call it rearranged_arr . The greatness of the array is the number of indices i for which rearranged_arr[i] > arr[i] . We want to find the maximum possible greatness that can be achieved by some rearrangement of the array. Examples Example 1: Input: arr = [1, 3, 5, 2, 1, 3] Output: 4 Explanation: Given the initial array arr , find the maximum possible greatness which can be achieved by some rearrangement of the array. [1, 3, 5, 2, 1, 3] -> original arr [2, 1, 3, 5, 3, 1] -> optimal rearranged_arr Here, at indices 0, 1, 3, and 4 in bold, rearranged_arr[i] > arr[i] . The total count for this is the maximum possible greatness. Thus, the answer is 4. Sample Case 0: Input: n = 6 arr = [1, 2, 3, 6, 2, 1] Output: 4 Explanation: The optimal rearranged_arr = [2, 3, 1, 6, 2, 1]. Here, all indices except 2 and 3 are great. Sample Case 1: Input: n = 4 arr = [4, 1, 6, 3] Output: 3 Explanation: