Sir my test case 3 is giving TLE can you tell where I am wrong?

#include<bits/stdc++.h>
using namespace std;

int main() {

int n;
cin>>n;
int a[n];
long long int x = 1e9 + 7;

unordered_set s;

for(int i = 0; i < n; i++) {
cin >> a[i];
}

int i = 0; int count = 0;
int j,sum;

while(i < n) {
j = i;
sum = 0;

   while((j < n) && (s.find(a[j]) == s.end())) {
        s.insert(a[j]);
        sum = ((sum % x) + (j - i + 1) % x) % x;
        j++;
   }
   count = ((count % x) + (sum % x)) % x;
   s.clear();
   i++;
}

cout << count <<endl;

return 0;
}

Hello @yashme7125 there are certain modifications required in your code:


please see this code.
if you have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.