Description
Solutions
Find Maximum Greatness
🤘 INTERN📚RELATED PROBLEMS
Given an array arr
, we can rearrange it to form another array, let's call it rearranged_arr
. The greatness of the array is defined as the number of indices i
, 0 ≤ i < n
, where rearranged_arr[i] > arr[i]
. That is, the element placed after rearrangement is greater than the initial value present at that index.
Given the initial array arr
, find the maximum possible greatness which can be achieved by some rearrangement of the array.
Function Description
Complete the function findMaximumGreatness
in the editor.
findMaximumGreatness
has the following parameter:
int arr[n]
: an array of integers
Returns
int: the maximum possible greatness
Example 1:
Input: arr = [1, 3, 5, 2, 1, 3, 1]
Output: 4
Explanation:[1, 3, 5, 2, 1, 3, 1]
-> originalarr
[2, 5, 1, 3, 3, 1, 1]
-> optimalrearranged_arr
Here, at indices0, 1, 3, and 4
in bold,rearranged_arr[i] > arr[i]
. It can be shown that this is the maximum possible greatness. Thus, the answer is4
.
Constraints:
1 ≤ n ≤ 105
1 ≤ arr[i] ≤ 109

Related Problems
Testcase
Result
Case 1
input:
output: