Javascript sliding window O(n) solution
\n/**\n * @param {string} s\n * @param {number} maxLetters\n * @param {number} minSize\n * @param {number} maxSize\n * @return {number}\n */\nvar maxFreq = func
```\n/**\n * @param {string} s\n * @param {number} maxLetters\n * @param {number} minSize\n * @param {number} maxSize\n * @return {number}\n */\nvar maxFreq = function(s, maxLetters, minSize, maxSize) {\n    let map = new Map(); // count all qualified substring\n    let start = 0;\n    let letters = new Map(); // count letter occurance between [i, start]\n    \n    for(let i = 0; i < s.length; ++i) {\n        letters.set(s[i], (letters.get(s[i]) || 0) + 1);\n        \n        if (i - start + 1 > minSize) { // try to move start forward\n            letters.set(s[start], letters.get(s[start]) - 1);\n            if (letters.get(s[start]) === 0) {\n                letters.delete(s[start]);\n            }\n            start++;\n        }      \n        // save the qualified substring into map\n        if (letters.size <= maxLetters && i - start + 1 >= minSize) {\n            let sub = s.substring(start, i + 1);\n            map.set(sub, (map.get(sub) || 0) + 1);\n        }\n    }\n    let max = 0;\n    [...map.entries()].map(([k, v]) => max = Math.max(max, v));\n    return max;\n};\n```
['JavaScript']