Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximize Greatness of an Array

XPChallenge Points: 20
levelLevel: Medium

You are given an integer array nums.
You may rearrange the values in any order to create a new array perm.

We define greatness as the count of indices i where:

perm[i] > nums[i]

Your task is to determine the highest number of such positions possible by choosing the best permutation of the array.

Return that maximum greatness value.

Example 1:

Input: nums = [2, 2, 1, 4]

Output: 2

Explanation:

One possible arrangement is perm = [4, 2, 2, 1]. perm[i] > nums[i] at indices 0 and 2. No permutation can achieve more than 2.

Example 2:

Input: nums = [5, 1, 3]

Output: 2

Explanation:

A valid permutation is perm = [3, 5, 1]. Greatness count = 2.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result