link to code : CodeChef: Practical coding for everyone
This is giving WA only for the first testcase. I am stuck here for more than a week . PLEASE HELP!
I have put comments in the code.
My approach:
storing the last index of the element, and also storing the freq of them. When the size of hashmap == k , i am removing the left element until the size < k and while removing, also decreasing the freq of that element. if during this, the freq becomes less than 1, it means that the element is no longer in the range left…right. So i remove it from both freq hashmap and hs hashmap