[With Explanation] Frequency + Sort
Code Explanation\n\nFill the Frequency Array: Iterate through each character of the input word and increment the count in corresponding position.\n\nSort the Fr
# Code Explanation\n\n**Fill the Frequency Array:** Iterate through each character of the input word and increment the count in corresponding position.\n\n**Sort the Frequency Array:** The count array is sorted so that it simplifies the process of calculating the minimum deletions required.\n\n**Calculate Minimum Deletions:** The idea is to fix a frequency, count[i], and calculate the cost to make all subsequent frequencies either equal to or not more than count[i] + k. This is done by iterating over the sorted frequency array and for each frequency:\n\nAdd up the frequencies (prefix_sum) as you move forward. This helps in calculating the deletions required for making frequencies equal to or less than count[i] + k.\n\nFor each frequency greater than count[i] + k, calculate the difference and add it to curr. This represents the deletions needed to decrease these frequencies to count[i] + k.\n\nUpdate the answer with the minimum of its current value and curr to keep track of the minimum deletions required.\n\n**Time Complexity :** O(n + 26log26) -> O(n)\n\n**Space Complexity :** O(26) -> O(1)\n\n# Code\n```\nclass Solution {\n    public int minimumDeletions(String word, int k) {\n        int count[]=new int[26];\n        \n        // Count the frequency of each character in the word\n        for(int i=0;i<word.length();i++)\n            count[word.charAt(i)-\'a\']++;\n        \n        // Sort the frequency array in ascending order\n        Arrays.sort(count);\n        \n        int answer=Integer.MAX_VALUE;\n\n        int prefix_sum=0;\n        \n        // Iterate over each character frequency\n        for (int i=0; i <count.length; i++) {\n            // Skip if character frequency is 0\n            if(count[i]==0)\n                continue;\n\n            // Current deletion count starts with prefix_sum\n            int curr=prefix_sum;\n            \n            // Check for characters with frequency higher than the limit (count[i] + k)\n            for (int j=i+1; j<count.length; j++) {\n                // If frequency is too high, calculate necessary deletions\n                if(count[j]>count[i]+k)\n                    curr+=count[j]-(count[i]+k);\n            }\n\n            // Update answer with the minimum deletion count found\n            answer=Math.min(answer,curr);\n            \n            // Update prefix_sum with the current character\'s frequency\n            prefix_sum+=count[i];\n        }\n    \n        // Return the minimum deletions required, or 0 if no deletions needed\n        return answer==Integer.MAX_VALUE?0:answer;\n    }\n}\n\n```
['Java']