EASYasked at 1 company

Maximum Difference Between Even and Odd Frequency I

A easy-tier problem at 61% community acceptance, tagged with Hash Table, String, Counting. Reported in interviews at Microsoft and 0 others.

Founder's read

You're asked to find the maximum difference between the frequency of even and odd-frequency characters in a string. It sounds straightforward until you hit the edge case where no even or odd frequencies exist, and suddenly your logic breaks. Microsoft and other companies ask this because it tests whether you can think through boundary conditions and use a hash table cleanly without overcomplicating the loop. The 61% acceptance rate reflects candidates who skip the edge cases. If this lands in your assessment and you blank on the indexing, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
1
Difficulty
EASY
Acceptance
61%

Companies that ask "Maximum Difference Between Even and Odd Frequency I"

If this hits your live OA

Maximum Difference Between Even and Odd Frequency I is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The pattern is simple but candidates miss it. Count the frequency of every character using a hash table, then iterate through frequencies and bucket them into even and odd categories. Track the max frequency in each bucket separately. The pitfall is assuming both buckets will have entries, if all characters appear an even number of times, the max odd frequency stays 0, and your answer is just the max even count. Another trap: confusing character frequency with character count, or trying to track frequencies on the fly instead of in a second pass. Since the input is just a string and the topics are Hash Table, String, and Counting, you're not dealing with complex data structures, your hash table is your main tool. The obvious approach works if you think step-by-step: count, partition, compare.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximum Difference Between Even and Odd Frequency I recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Difference Between Even and Odd Frequency I interview FAQ

Is this problem really easy or harder than the label suggests?+

The mechanics are easy, but the 61% acceptance tells you many candidates fail edge cases. If all characters appear an even number of times, returning 0 for odd-frequency difference is correct. Missing that case drops your acceptance immediately. The algorithm itself is O(n), not the bottleneck.

When would I actually see this in a real interview?+

Microsoft has asked it. Given the low company count and EASY tag, it's less likely than core hash table problems, but it's a common warm-up or second question in screening rounds. It tests whether you code carefully and handle boundaries, not whether you know exotic patterns.

What's the trick to avoiding off-by-one errors here?+

Initialize your max even and max odd to 0, not negative infinity. If no odd frequencies exist, max odd stays 0 and that's correct. Build your frequency map first, then iterate through it once. Don't try to update both max values in the same loop as counting.

Do I need to optimize further after the hash table pass?+

No. You count characters in O(n) time, iterate through the hash table in O(k) time where k is the alphabet size, then iterate frequencies in O(k) again. Space is O(k). That's optimal for the problem. Further optimization adds no value.

How does this relate to the other Hash Table and String topics?+

It's a direct application of hash table counting with a string input. No advanced string manipulation, no KMP or pattern matching. It's Hash Table 101, which makes it a good signal that you can use basic data structures correctly before you attempt harder string problems.

Want the actual problem statement? View "Maximum Difference Between Even and Odd Frequency I" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.