3692. Majority Frequency Characters Easy

@problem@discussion
#Hash Table#String#Counting



1/**
2 * [3692] Majority Frequency Characters
3 *
4 * You are given a string s consisting of lowercase English letters.
5 * The frequency group for a value k is the set of characters that appear exactly k times in s.
6 * The majority frequency group is the frequency group that contains the largest number of distinct characters.
7 * Return a string containing all characters in the majority frequency group, in any order. If two or more frequency groups tie for that largest size, pick the group whose frequency k is larger.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">s = "aaabbbccdddde"</span>
12 * Output: <span class="example-io">"ab"</span>
13 * Explanation:
14 * <table style="border: 1px solid black;">
15 * 	<thead>
16 * 		<tr>
17 * 			<th style="border: 1px solid black;">Frequency (k)</th>
18 * 			<th style="border: 1px solid black;">Distinct characters in group</th>
19 * 			<th style="border: 1px solid black;">Group size</th>
20 * 			<th style="border: 1px solid black;">Majority?</th>
21 * 		</tr>
22 * 	</thead>
23 * 	<tbody>
24 * 		<tr>
25 * 			<td style="border: 1px solid black;">4</td>
26 * 			<td style="border: 1px solid black;">{d}</td>
27 * 			<td style="border: 1px solid black;">1</td>
28 * 			<td style="border: 1px solid black;">No</td>
29 * 		</tr>
30 * 		<tr>
31 * 			<td style="border: 1px solid black;">3</td>
32 * 			<td style="border: 1px solid black;">{a, b}</td>
33 * 			<td style="border: 1px solid black;">2</td>
34 * 			<td style="border: 1px solid black;">Yes</td>
35 * 		</tr>
36 * 		<tr>
37 * 			<td style="border: 1px solid black;">2</td>
38 * 			<td style="border: 1px solid black;">{c}</td>
39 * 			<td style="border: 1px solid black;">1</td>
40 * 			<td style="border: 1px solid black;">No</td>
41 * 		</tr>
42 * 		<tr>
43 * 			<td style="border: 1px solid black;">1</td>
44 * 			<td style="border: 1px solid black;">{e}</td>
45 * 			<td style="border: 1px solid black;">1</td>
46 * 			<td style="border: 1px solid black;">No</td>
47 * 		</tr>
48 * 	</tbody>
49 * </table>
50 * Both characters 'a' and 'b' share the same frequency 3, they are in the majority frequency group. "ba" is also a valid answer.
51 * </div>
52 * <strong class="example">Example 2:
53 * <div class="example-block">
54 * Input: <span class="example-io">s = "abcd"</span>
55 * Output: <span class="example-io">"abcd"</span>
56 * Explanation:
57 * <table style="border: 1px solid black;">
58 * 	<thead>
59 * 		<tr>
60 * 			<th style="border: 1px solid black;">Frequency (k)</th>
61 * 			<th style="border: 1px solid black;">Distinct characters in group</th>
62 * 			<th style="border: 1px solid black;">Group size</th>
63 * 			<th style="border: 1px solid black;">Majority?</th>
64 * 		</tr>
65 * 	</thead>
66 * 	<tbody>
67 * 		<tr>
68 * 			<td style="border: 1px solid black;">1</td>
69 * 			<td style="border: 1px solid black;">{a, b, c, d}</td>
70 * 			<td style="border: 1px solid black;">4</td>
71 * 			<td style="border: 1px solid black;">Yes</td>
72 * 		</tr>
73 * 	</tbody>
74 * </table>
75 * All characters share the same frequency 1, they are all in the majority frequency group.
76 * </div>
77 * <strong class="example">Example 3:
78 * <div class="example-block">
79 * Input: <span class="example-io">s = "pfpfgi"</span>
80 * Output: <span class="example-io">"fp"</span>
81 * Explanation:
82 * <table style="border: 1px solid black;">
83 * 	<thead>
84 * 		<tr>
85 * 			<th style="border: 1px solid black;">Frequency (k)</th>
86 * 			<th style="border: 1px solid black;">Distinct characters in group</th>
87 * 			<th style="border: 1px solid black;">Group size</th>
88 * 			<th style="border: 1px solid black;">Majority?</th>
89 * 		</tr>
90 * 	</thead>
91 * 	<tbody>
92 * 		<tr>
93 * 			<td style="border: 1px solid black;">2</td>
94 * 			<td style="border: 1px solid black;">{p, f}</td>
95 * 			<td style="border: 1px solid black;">2</td>
96 * 			<td style="border: 1px solid black;">Yes</td>
97 * 		</tr>
98 * 		<tr>
99 * 			<td style="border: 1px solid black;">1</td>
100 * 			<td style="border: 1px solid black;">{g, i}</td>
101 * 			<td style="border: 1px solid black;">2</td>
102 * 			<td style="border: 1px solid black;">No (tied size, lower frequency)</td>
103 * 		</tr>
104 * 	</tbody>
105 * </table>
106 * Both characters 'p' and 'f' share the same frequency 2, they are in the majority frequency group. There is a tie in group size with frequency 1, but we pick the higher frequency: 2.
107 * </div>
108 *  
109 * Constraints:
110 * 
111 * 	1 <= s.length <= 100
112 * 	s consists only of lowercase English letters.
113 * 
114 */
115pub struct Solution {}
116
117// problem: https://leetcode.com/problems/majority-frequency-characters/
118// discuss: https://leetcode.com/problems/majority-frequency-characters/discuss/?currentPage=1&orderBy=most_votes&query=
119
120// submission codes start here
121
122impl Solution {
123    pub fn majority_frequency_group(s: String) -> String {
124        String::new()
125    }
126}
127
128// submission codes end
129
130#[cfg(test)]
131mod tests {
132    use super::*;
133
134    #[test]
135    fn test_3692() {
136    }
137}
138

Back
© 2026 bowen.ge All Rights Reserved.