1647. Minimum Deletions to Make Character Frequencies Unique Medium
1/**
2 * [1647] Minimum Deletions to Make Character Frequencies Unique
3 *
4 * A string s is called good if there are no two different characters in s that have the same frequency.
5 * Given a string s, return the minimum number of characters you need to delete to make s good.
6 * The frequency of a character in a string is the number of times it appears in the string. For example, in the string "aab", the frequency of 'a' is 2, while the frequency of 'b' is 1.
7 *
8 * Example 1:
9 *
10 * Input: s = "aab"
11 * Output: 0
12 * Explanation: s is already good.
13 *
14 * Example 2:
15 *
16 * Input: s = "aaabbbcc"
17 * Output: 2
18 * Explanation: You can delete two 'b's resulting in the good string "aaabcc".
19 * Another way it to delete one 'b' and one 'c' resulting in the good string "aaabbc".
20 * Example 3:
21 *
22 * Input: s = "ceabaacb"
23 * Output: 2
24 * Explanation: You can delete both 'c's resulting in the good string "eabaab".
25 * Note that we only care about characters that are still in the string at the end (i.e. frequency of 0 is ignored).
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= s.length <= 10^5
31 * s contains only lowercase English letters.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/
37// discuss: https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn min_deletions(s: String) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_1647() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.