Skip to main content
LeetCode 3442, Easy. Topics: Hash Table, String, Counting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 26 parametrized pytest cases, and a playground notebook:

Problem

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.

Examples

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.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026