|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/?envType=daily-question&envId=2025-06-10">3442. Maximum Difference Between Even and Odd Frequency I</a></h2><h3>Easy</h3><hr><p>You are given a string <code>s</code> consisting of lowercase English letters.</p> |
| 2 | + |
| 3 | +<p>Your task is to find the <strong>maximum</strong> difference <code>diff = freq(a<sub>1)</sub> - freq(a<sub>2</sub>)</code> between the frequency of characters <code>a<sub>1</sub></code> and <code>a<sub>2</sub></code> in the string such that:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li><code>a<sub>1</sub></code> has an <strong>odd frequency</strong> in the string.</li> |
| 7 | + <li><code>a<sub>2</sub></code> has an <strong>even frequency</strong> in the string.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>Return this <strong>maximum</strong> difference.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<div class="example-block"> |
| 16 | +<p><strong>Input:</strong> <span class="example-io">s = "aaaaabbc"</span></p> |
| 17 | + |
| 18 | +<p><strong>Output:</strong> 3</p> |
| 19 | + |
| 20 | +<p><strong>Explanation:</strong></p> |
| 21 | + |
| 22 | +<ul> |
| 23 | + <li>The character <code>'a'</code> has an <strong>odd frequency</strong> of <code><font face="monospace">5</font></code><font face="monospace">,</font> and <code>'b'</code> has an <strong>even frequency</strong> of <code><font face="monospace">2</font></code>.</li> |
| 24 | + <li>The maximum difference is <code>5 - 2 = 3</code>.</li> |
| 25 | +</ul> |
| 26 | +</div> |
| 27 | + |
| 28 | +<p><strong class="example">Example 2:</strong></p> |
| 29 | + |
| 30 | +<div class="example-block"> |
| 31 | +<p><strong>Input:</strong> <span class="example-io">s = "abcabcab"</span></p> |
| 32 | + |
| 33 | +<p><strong>Output:</strong> 1</p> |
| 34 | + |
| 35 | +<p><strong>Explanation:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li>The character <code>'a'</code> has an <strong>odd frequency</strong> of <code><font face="monospace">3</font></code><font face="monospace">,</font> and <code>'c'</code> has an <strong>even frequency</strong> of <font face="monospace">2</font>.</li> |
| 39 | + <li>The maximum difference is <code>3 - 2 = 1</code>.</li> |
| 40 | +</ul> |
| 41 | +</div> |
| 42 | + |
| 43 | +<p> </p> |
| 44 | +<p><strong>Constraints:</strong></p> |
| 45 | + |
| 46 | +<ul> |
| 47 | + <li><code>3 <= s.length <= 100</code></li> |
| 48 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 49 | + <li><code>s</code> contains at least one character with an odd frequency and one with an even frequency.</li> |
| 50 | +</ul> |
0 commit comments