O(n) Soln
Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code
# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python []\nclass Solution:\n    def minimumDeletions(self, word: str, k: int) -> int:\n        map, ans = [0] * 26, float(\'inf\')\n        for ch in word: map[ord(ch) - 97] += 1\n        for x in map:\n            current_sum = 0\n            for y in map:\n                if y > x + k: current_sum += (y - x - k)\n                elif y < x: current_sum += y\n            ans = min(ans, current_sum)\n        return ans\n```\n``` rust []\nimpl Solution {\n    pub fn minimum_deletions(word: String, k: i32) -> i32 {\n        let (mut map, mut ans) = ([0; 26], i32::MAX);\n        for ch in word.chars() { map[ch as usize - 97] += 1; }\n        for &x in map.iter() {\n            ans = ans.min(\n                map.iter().map(|&y| {\n                    if y > x + k { y - x - k }\n                    else if y < x { y }\n                    else { 0 }\n                }).sum()\n            );\n        }\n        ans\n    }\n}\n```\n``` java []\nfinal class Solution {\n    public int minimumDeletions(final String word, final int k) {\n        final int[] map = new int[26];\n        var ans = Integer.MAX_VALUE;\n        for (final char ch : word.toCharArray()) map[ch - 97] += 1;\n        for (final int x : map) {\n            var currentSum = 0;\n            for (final int y : map) \n                if (y > x + k) currentSum += (y - x - k);\n                else if (y < x) currentSum += y;\n            ans = Math.min(ans, currentSum);\n        }return ans;\n    }\n}\n```\n
['Java', 'Python3', 'Rust']