Calculate the longest consecutive subsequence

I have written a code to calculate on how to calculate the longest consecutive subsequence .Pls help me where i am wrong.Here is my code

#include
#include
#include
using namespace std;
int longest_subsequence(int a[],int n){

map<int,int>m;
for(int i=0;i<n;i++){
    m.insert(make_pair(i,a[i]));
}
int p,q,ans;
ans=0;
int cnt=0;
p=a[0];
q=a[n-1];
 for(int i=p;i<=q;i++){
    if(m.count(i)>0){
        cnt++;
    }
    else{
        ans=max(ans,cnt);
        cnt=0;
        continue;
    }
 }
 return ans;

}
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cout<<longest_subsequence(a,n)<<endl;
return 0;
}

hi @swatantra1240_25a488bfc859a4ab match with video once

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.

I did not find any video to match my code. Are you talking to match class lecture .