Ctrl K

Odd Count Minus Even Count

Easy
You are given a string text of lowercase English letters. For every letter that appears in it, count how many times it appears. Pick two letters: the first must appear an odd number of times, the second an even number of times. Make the difference "count of the first minus count of the second" as large as possible and return it (it may come out negative). The string is guaranteed to contain at least one letter with an odd count and at least one with an even count.
Example 1
text='mississippi' → -1

"m" occurs once, "i" and "s" four times each, "p" twice. The odd counts are 1; the even ones are 4, 4 and 2. The best difference is 1 - 2 = -1.

Example 2
text='zzzzzxxyw' → 3

"z" occurs 5 times (odd) and "x" twice (even): 5 - 2 = 3.

Constraints
  • 3 ≤ len(text) ≤ 100
  • text consists only of lowercase English letters
  • Some letter has an odd count and some letter has an even count
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNote From Clipped Letters EasyFirst One-Off Letter EasyWords Heard Only Once EasyWords From Letter Tiles EasyBalloon Signs From Letters Easy
loading Python…
Input
text='mississippi'
Expected
-1

Run checks the first 3 tests in your browser. Submit checks all 30 tests on the server, hidden ones included.