Fixed size window - C++ Iterators
Original approach: \n\n Sliding window approach\n Check if constraints met, add to string counter map\n if size < minSize, move right side of window\n if unique
## Original approach: \n\n* Sliding window approach\n* Check if constraints met, add to string counter map\n* if size < minSize, move right side of window\n* if uniqueChars > maxLetters move left side of window\n* if size > maxSize, move left side of window\n* Use `unordered_map.size()` to count the number of unique characters.\n* When moving the right iterator, increment character count\n* When moving the left iterator, decrement character count and erase if frequency is zero (so `unordered_map.size()` works)\n* iterate through map and find max freq\n\n## Optimized approach\n\n* Maximum frequency string always occurs with string of minimum size. This is b/c all strings with frequency f and size > minSize, contain substrings with frequency >= f and size == minSize.\n* Therefore the size of the sliding window can be fixed at size minSize. This eliminates the need to check size for validity and simplifies iteration.\n\n```C++\nint maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n   \n    unordered_map<string, int> stringCount;\n    unordered_map<char, int> uniqueChars;\n\n    // left side of sliding window\n    auto leftIt = s.begin();\n\n    // right side of sliding window\n    auto rightIt = s.begin();\n    while (rightIt != s.end() && rightIt - leftIt < minSize) {\n        ++uniqueChars[*rightIt];\n        ++rightIt;\n    }\n\n    // iterate until window reaches end of string\n    while (s.end() - leftIt >= minSize) {\n        // check if valid string\n        if (uniqueChars.size() <= maxLetters) {\n            ++stringCount[string(leftIt, rightIt)];\n        }\n\n        // decrement characters falling out of the string and increment character being added to string\n        // note: rightIt is not included in the string so add the character at right iterator before moving iterator\n        --uniqueChars[*leftIt];\n        if (uniqueChars[*leftIt] == 0) {\n            uniqueChars.erase(*leftIt);\n        }\n        ++leftIt;\n\t\tif (rightIt != s.end()) {\n\t\t\t++uniqueChars[*rightIt];\n\t\t\t++rightIt;\n\t\t}\n\n    }\n\n    // iterate through map and find maximum frequency string\n    int maxFreq = 0;\n    for (auto& kv : stringCount) {\n        maxFreq = max(maxFreq, kv.second);\n    }\n    return maxFreq;\n```
['C', 'Sliding Window']