2423. Remove Letter To Equalize Frequency Easy
1/**
2 * [2423] Remove Letter To Equalize Frequency
3 *
4 * You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.
5 * Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.
6 * Note:
7 *
8 * The frequency of a letter x is the number of times it occurs in the string.
9 * You must remove exactly one letter and cannot chose to do nothing.
10 *
11 *
12 * Example 1:
13 *
14 * Input: word = "abcc"
15 * Output: true
16 * Explanation: Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.
17 *
18 * Example 2:
19 *
20 * Input: word = "aazz"
21 * Output: false
22 * Explanation: We must delete a character, so either the frequency of "a" is 1 and the frequency of "z" is 2, or vice versa. It is impossible to make all present letters have equal frequency.
23 *
24 *
25 * Constraints:
26 *
27 * 2 <= word.length <= 100
28 * word consists of lowercase English letters only.
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/remove-letter-to-equalize-frequency/
34// discuss: https://leetcode.com/problems/remove-letter-to-equalize-frequency/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn equal_frequency(word: String) -> bool {
40 false
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_2423() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.