Playlist Problem CSES

Problem link: CSES - Playlist
Code link: https://cses.fi/paste/408cea2327e7ddb2130854/

I am using 2 pointers + sliding window technique. But I am getting a TLE in some cases. Can someone pls tell me what I am doing wrong? Or is this approach inefficient.

Approach I used


Keep on increasing window length, while we have string a with unique characters.
As soon as we find a duplicate, we delete from the array till the string does not contain duplicate

u can use the map

#include<bits/stdc++.h>

using namespace std;
int a[10000000];
map<int,int> mp;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    long long ans=0,j=0;
    for(int i=0;i<n;i++)
    {
        if(mp[a[i]]>=1)
            while(mp[a[i]]>0)
        {
            mp[a[j]]--;
            j++;
        }
        mp[a[i]]++;
        ans=max(ans,i-j+1);
    }
    cout<<ans;
    return 0;
}

Can anyone explain why std::map gets accepted? I had tried std::unordered_set and std::unordered_map both gave TLE on the last test case.