3442. Maximum Difference Between Even and Odd Frequency I Easy
1/**
2 * [3442] Maximum Difference Between Even and Odd Frequency I
3 *
4 * You are given a string s consisting of lowercase English letters. Your task is to find the maximum difference between the frequency of two characters in the string such that:
5 *
6 * One of the characters has an even frequency in the string.
7 * The other character has an odd frequency in the string.
8 *
9 * Return the maximum difference, calculated as the frequency of the character with an odd frequency minus the frequency of the character with an even frequency.
10 *
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">s = "aaaaabbc"</span>
14 * Output: 3
15 * Explanation:
16 *
17 * The character 'a' has an odd frequency of <font face="monospace">5</font><font face="monospace">,</font> and 'b' has an even frequency of <font face="monospace">2</font>.
18 * The maximum difference is 5 - 2 = 3.
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">s = "abcabcab"</span>
23 * Output: 1
24 * Explanation:
25 *
26 * The character 'a' has an odd frequency of <font face="monospace">3</font><font face="monospace">,</font> and 'c' has an even frequency of <font face="monospace">2</font>.
27 * The maximum difference is 3 - 2 = 1.
28 * </div>
29 *
30 * Constraints:
31 *
32 * 3 <= s.length <= 100
33 * s consists only of lowercase English letters.
34 * s contains at least one character with an odd frequency and one with an even frequency.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/
40// discuss: https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn max_difference(s: String) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_3442() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.