images | notes | c++ | greedy
Notes\n\n\n\n# Code\n\nclass Solution {\npublic:\n    int minimumDeletions(string word, int k) {\n        int ans = word.length();\n        vector<int> freq(26,
# Notes\n![IMG_20240422_180454.jpg](https://assets.leetcode.com/users/images/f96b08c8-5734-4444-ab97-93d37e1368ce_1713789547.8194153.jpeg)\n![IMG_20240422_180502.jpg](https://assets.leetcode.com/users/images/a6ca4ff2-ce7a-4e95-b818-adb2c0d4abf0_1713789534.9360988.jpeg)\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumDeletions(string word, int k) {\n        int ans = word.length();\n        vector<int> freq(26,0);\n        for(char ch: word){\n            freq[ch-\'a\']++;\n        }\n\n        for(int i=0;i<26;i++){\n            int del=0;\n            for(int j=0;j<26;j++){\n                if(i==j) continue;\n\n                if(freq[j]<freq[i]){\n                    del += freq[j];//del all freq of a particular character\n                }\n                else if(abs(freq[i]-freq[j])>k){\n                    del += abs(freq[i]-freq[j])-k;\n                }\n            }\n            ans = min(ans,del);\n        }\n        return ans;\n    }\n};\n```
['Hash Table', 'String', 'Greedy', 'Sorting', 'Counting', 'C++']