Maximum Difference Between Even and Odd Frequency I
Easy
You receive 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 text such that:
-
a1has an odd frequency in the text. -
a2has an even frequency in the text.
Produce this maximum difference.
Example 1
Input: s = "aaaaabbc"
Output: 3
Explanation:
-
The character
'a'has an odd frequency of5, and'b'has an even frequency of2. -
The maximum difference is
5 - 2 = 3.
Example 2
Input: s = "abcabcab"
Output: 1
Explanation:
-
The character
'a'has an odd frequency of3, and'c'has an even frequency of 2. -
The maximum difference is
3 - 2 = 1.
Constraints
3 <= s.length <= 100sconsists only of lowercase English letters.scontains at least one character with an odd frequency and one with an even frequency.
Did this problem appear in one of your interviews?
Responses stay private.
