|
| 1 | +<p>You are given a string <code>s</code> consisting of lowercase English letters. Your task is to find the <strong>maximum</strong> difference between the frequency of <strong>two</strong> characters in the string such that:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>One of the characters has an <strong>even frequency</strong> in the string.</li> |
| 5 | + <li>The other character has an <strong>odd frequency</strong> in the string.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>Return the <strong>maximum</strong> difference, calculated as the frequency of the character with an <b>odd</b> frequency <strong>minus</strong> the frequency of the character with an <b>even</b> frequency.</p> |
| 9 | + |
| 10 | +<p> </p> |
| 11 | +<p><strong class="example">Example 1:</strong></p> |
| 12 | + |
| 13 | +<div class="example-block"> |
| 14 | +<p><strong>Input:</strong> <span class="example-io">s = "aaaaabbc"</span></p> |
| 15 | + |
| 16 | +<p><strong>Output:</strong> 3</p> |
| 17 | + |
| 18 | +<p><strong>Explanation:</strong></p> |
| 19 | + |
| 20 | +<ul> |
| 21 | + <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> |
| 22 | + <li>The maximum difference is <code>5 - 2 = 3</code>.</li> |
| 23 | +</ul> |
| 24 | +</div> |
| 25 | + |
| 26 | +<p><strong class="example">Example 2:</strong></p> |
| 27 | + |
| 28 | +<div class="example-block"> |
| 29 | +<p><strong>Input:</strong> <span class="example-io">s = "abcabcab"</span></p> |
| 30 | + |
| 31 | +<p><strong>Output:</strong> 1</p> |
| 32 | + |
| 33 | +<p><strong>Explanation:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <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> |
| 37 | + <li>The maximum difference is <code>3 - 2 = 1</code>.</li> |
| 38 | +</ul> |
| 39 | +</div> |
| 40 | + |
| 41 | +<p> </p> |
| 42 | +<p><strong>Constraints:</strong></p> |
| 43 | + |
| 44 | +<ul> |
| 45 | + <li><code>3 <= s.length <= 100</code></li> |
| 46 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 47 | + <li><code>s</code> contains at least one character with an odd frequency and one with an even frequency.</li> |
| 48 | +</ul> |
0 commit comments