Intuitive recursion-based, whether to delete the least frequency one or keep it.
Intuition\nAfter sorting by the frequencies in descrending order, recursively consider keeping the letter with the least frequency or delete it.\n\n# Approach\n
# Intuition\nAfter sorting by the frequencies in descrending order, recursively consider keeping the letter with the least frequency or delete it.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count the frequencies for 26 letters\n2. Sort the frequencies in descrending order\n3. Two ways to find the final answer:\n    - keep the least frequency and figure out the number of letters to be deleted.\n    - delete the letter with the least frequency, and do the recursion for step 3.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(N)$$, needs to traverse the word string to get frequencies.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$, again, word size does not affect the space.\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumDeletions(string word, int k) {\n        int res = 0;\n        vector<int> cnt(26, 0);\n        int n = word.size();\n        for (int i = 0; i < n; i++) {\n            cnt[word[i]-\'a\']++;\n        }\n        vector<int> freq;\n        for (auto x : cnt) {\n            if (x > 0) {\n                freq.push_back(x);\n            }\n        }\n        sort(freq.rbegin(), freq.rend());\n        // for (auto x : freq) {\n        //     cout << x << " ";\n        // }\n        func(freq, freq.size(), k, res);\n        return res;\n    }\n    \n    int func(vector<int> freq, int n, int k, int& res) {\n        if (n == 0) return 0;\n        if (n == 1) return 0;\n        int last = freq[n-1];\n        int next = func(freq, n-1, k, res)+last;\n        \n        for (int i = 0; i < n; i++) {\n            freq[i] -= last;\n        }\n        int tmp = 0;\n        for (int i = 0; i < n; i++) {\n            tmp += max(0, freq[i]-k); \n        }\n        res = min(tmp, next);\n        return res;\n    }\n};\n```
['C++']