[C++] O(NK) Sliding modification with detailed explanation
We used a map to keep track of the last apperance index of a character. \nThen we move the right in outer layer to update the map. \nIf we have more than K elem
We used a map to keep track of the **last apperance index of a character**. \nThen we move the **right** in outer layer to update the map. \nIf we have more than K element inside the window, move the **left** curosr, decrease number and update the map.\nWhen the map have exactly K element, loop through the map to find out the **minIndex** of the map.  \n#### ***Any window start between [left, minIndex] and end with right is a qualified answer.***\nTime complexity **O(NK)**, each element is put/pop from the sliding windows/map only once, each iteration might loop throguh all k element in the map.\nSpace complexity **O(K)**, for the map keep track of last apperance of each K element.\n```\nint subarraysWithKDistinct(vector<int>& A, int K) {\n    int answer = 0;\n    unordered_map<int, int> m;\n    int left = 0;\n    int right = 0;\n    while(right < A.size()) {                   // each element is only put into windows once\n        m[A[right]] = right;\n\n        while (m.size() > K) {                 \n            if (m[A[left]] == left)             // A[left] can be removed from the map if left is the last apperance\n                m.erase(A[left]);\n            left++;                             // each element is only pop from windows once\n        }\n        if (m.size() == K) {\n            int minIndex = right;\n            for (auto i : m)                    // find the minIndex of the map\n                minIndex = min(minIndex, i.second);\n            answer += minIndex - left + 1;      // Any window start between [left, minIndex] and end with right is a qualified answer.\n        }\n        right++;\n    }\n    return answer;\n}\n```
[]