Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Tan12d/583d253d461c640bc7d8c7b5eeb5a49b to your computer and use it in GitHub Desktop.
Save Tan12d/583d253d461c640bc7d8c7b5eeb5a49b to your computer and use it in GitHub Desktop.
Leetcode 3442 | Maximum Difference Between Even and Odd Frequency I
class Solution {
public int maxDifference(String s)
{
int freq[] = new int[26];
for(char c: s.toCharArray())
{
freq[c-'a']++;
}
int minEvenFreq = Integer.MAX_VALUE;
int maxOddFreq = Integer.MIN_VALUE;
for(int i: freq)
{
if((i&1)==0 && i!=0 && i<minEvenFreq)
{
minEvenFreq=i;
}
if((i&1)==1 && i>maxOddFreq)
{
maxOddFreq=i;
}
}
return maxOddFreq-minEvenFreq;
}
}
@Tan12d
Copy link
Author

Tan12d commented Jun 10, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment