3442.js
/** ------------------------------------------------------------------------------
*
* 3442. Maximum Difference Between Even and Odd Frequency I
* Topics: Hash Table
* https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/description/?envType=daily-question&envId=2025-06-10
*
------------------------------------------------------------------------------ */
/**
* @param {string} s
* @return {number}
*/
var maxDifference = function (s) {
const map = new Map()
let odd = -Infinity
let even = Infinity
for (const word of s) {
/* map[word] = (map[word] || 0) + 1; */
map.set(word, (map.get(word) || 0) + 1)
}
for (const word of map.values()) {
if (word % 2 !== 0) {
odd = Math.max(odd, word)
} else {
even = Math.min(even, word)
}
}
return odd - even
}
console.log(maxDifference("aaaaabbc"))