TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2664,3 "name": "maximize_greatness_of_an_array",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/maximize-greatness-of-an-array/",6 "date": "1677888000000",7 "task_description": "You are given a 0-indexed integer array `nums`. You are allowed to permute `nums` into a new array `perm` of your choosing. We define the **greatness** of `nums` be the number of indices `0 <= i < nums.length` for which `perm[i] > nums[i]`. Return _the **maximum** possible greatness you can achieve after permuting_ `nums`. **Example 1:** ``` **Input:** nums = [1,3,5,2,1,3,1] **Output:** 4 **Explanation:** One of the optimal rearrangements is perm = [2,5,1,3,3,1,1]. At indices = 0, 1, 3, and 4, perm[i] > nums[i]. Hence, we return 4. ``` **Example 2:** ``` **Input:** nums = [1,2,3,4] **Output:** 3 **Explanation:** We can prove the optimal perm is [2,3,4,1]. At indices = 0, 1, and 2, perm[i] > nums[i]. Hence, we return 3. ``` **Constraints:** `1 <= nums.length <= 105` `0 <= nums[i] <= 109`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [1,3,5,2,1,3,1]",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "nums = [1,2,3,4]",17 "output": "3 "18 }19 ],20 "private_test_cases": [],21 "haskell_template": "maximizeGreatness :: [Int] -> Int\nmaximizeGreatness nums ",22 "ocaml_template": "let maximizeGreatness (nums: int list) : int = ",23 "scala_template": "def maximizeGreatness(nums: List[Int]): Int = { \n \n}",24 "java_template": "public static int maximizeGreatness(List<Integer> nums) {\n\n}",25 "python_template": "class Solution(object):\n def maximizeGreatness(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n "26}