Easy C++ solution | Beats 100% solutions
Intuition\nCalculate the frequencies of all characters in the string. Since we can only delete a character (that is reduce the frequency of character), we can l
# Intuition\nCalculate the frequencies of all characters in the string. Since we can only delete a character (that is reduce the frequency of character), we can loop for all frequencies of chars keeping an `target` value and adjusting all frequencies suitable to that `target`. If for a `target`, the freq of char is less than `target`, we have to make its frequency `0` (as we can not increase freq), otherwise if freq of char is greater than `target`, we need to make sure it should not greater than `target + k`.\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumDeletions(string word, int k) {\n        vector<int> freq(26, 0);  \n        \n        for(char c : word){\n            freq[c - \'a\']++;\n        }\n        \n        int res = INT_MAX;\n        \n        for(int i=0; i < 26; i++){\n            int target = freq[i];\n            if(target == 0) continue;\n            int currCost = 0;\n\n            for(int a : freq){\n                // maintain \'a\' within the range [target, target + k]\n                if(a < target){\n                    currCost += a;\n                }\n                else if(a > target + k){\n                    currCost += a - target - k;\n                }\n            }\n\n            res = min(res, currCost);\n        }\n\n        return res;\n        \n    }\n};\n```\n\nimage.png![image.png](https://assets.leetcode.com/users/images/66e7d5a7-d16e-4550-806d-df21afd174b9_1710735635.9305475.png)\n
['C++']