#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j;
cin>>n;
unordered_sets;
int a[n+1];
for(i=0;i<n;i++)
cin>>a[i];
i=0,j=0;
int sum=0;
while(i<n)
{
int k1=1;
s.insert(a[i]);
j=i+1;
while(s.find(a[j])==s.end() && j<n)
{
k1=k1+1;
j=j+1;
}
s.erase(a[i]);
sum=(sum+((j-i)*(j-i+1))/2)%1000000007;
i=i+1;
}
cout<<sum<<endl;
}
Subarray with distinct element(what mistake have i done?)
Please try to dry run your code with sample input:
3
1 2 3
And then with sample input :
3
1 2 3 3
Answers are 10 and 11 respectively but your code give 10 and 10.
You will find your mistake 
Please have a look at this sample code if you still are unable to decode yourself. .
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.