Maximum Difference Between Even and Odd Frequency I

You are given a string s consisting of lowercase English letters.

Your task is to find the maximum difference diff = freq(a1) - freq(a2) between the frequency of characters a1 and a2 in the string such that:

  • a1 has an odd frequency in the string.
  • a2 has an even frequency in the string.

Return this maximum difference.

Example 1
Inputs = "aaaaabbc"
Output3
The character 'a' has an odd frequency of 5, 'b' has an even frequency of 2, and the maximum difference is 5 - 2 = 3.
Example 2
Inputs = "abcabcab"
Output1
The character 'a' has an odd frequency of 3, 'c' has an even frequency of 2, and the maximum difference is 3 - 2 = 1.

Constraints

  • 3 <= s.length <= 100
  • s consists only of lowercase English letters.
  • s contains at least one character with an odd frequency and one with an even frequency.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate