Created
June 10, 2025 17:03
-
-
Save Tan12d/583d253d461c640bc7d8c7b5eeb5a49b to your computer and use it in GitHub Desktop.
Leetcode 3442 | Maximum Difference Between Even and Odd Frequency I
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important Links & Files
Leetcode Question Link
Leetcode Solution Link
LinkedIn Post Link