Skip to content

Commit 4c37063

Browse files
committed
2423. Remove Letter To Equalize Frequency: RETRY
1 parent b56073c commit 4c37063

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,3 +1837,4 @@ mod s2418_sort_the_people;
18371837
mod s2419_longest_subarray_with_maximum_bitwise_and;
18381838
mod s2420_find_all_good_indices;
18391839
mod s2421_number_of_good_paths;
1840+
mod s2423_remove_letter_to_equalize_frequency;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 choose 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+
*/
31+
pub 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+
38+
impl Solution {
39+
pub fn equal_frequency(word: String) -> bool {
40+
false
41+
}
42+
}
43+
44+
// submission codes end
45+
46+
#[cfg(test)]
47+
mod tests {
48+
use super::*;
49+
50+
#[test]
51+
#[ignore]
52+
fn test_2423_example_1() {
53+
let word = "abcc".to_string();
54+
55+
let result = true;
56+
57+
assert_eq!(Solution::equal_frequency(word), result);
58+
}
59+
60+
#[test]
61+
#[ignore]
62+
fn test_2423_example_2() {
63+
let word = "aazz".to_string();
64+
65+
let result = false;
66+
67+
assert_eq!(Solution::equal_frequency(word), result);
68+
}
69+
}

0 commit comments

Comments
 (0)