Skip to content

Commit

Permalink
Create playlist.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukulguptaiit committed Jan 29, 2025
1 parent e0ac004 commit abc8936
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions playlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin>>t;
long long arr[t];
long long p=t;
while(t--){
cin>>arr[t];
}
long long count=1;
map<long long ,long long > s;
s[arr[0]]=0;
long long i=0;
long long j=1;
while(j<p){
if(s.find(arr[j])==s.end()){
s[arr[j]]=j;
j++;
}else{
if(s[arr[j]]>=i)i=s[arr[j]]+1;
s[arr[j]]=j;
j++;
}
count=max(count,j-i);
}cout<<count;
return 0;
}

0 comments on commit abc8936

Please sign in to comment.