Chef and Numbers https://www.codechef.com/RC122020/problems/RECNDNOS

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

int main(){
int t;cin>>t;
while(t–){
int n;cin>>n;
int arr[n],dp[n];
for(int i=0;i<n;i++){cin>>arr[i];dp[i]=1;}
//getting the dp started
int max_ele = n-1;
for(int i=(n-3);i>=0;i–){
for(int j=i+2;j<n;j++){
if(arr[j]==arr[i] && dp[j]+1>dp[i])
dp[i]=(dp[j]+1);
}
if(dp[max_ele]<dp[i] || (dp[max_ele]==dp[i] && arr[max_ele]>arr[i]))
max_ele=i;
}
cout<<arr[max_ele]<<endl;
}return 0;
}

this is my code but i am not able to understand which test case it’s failing or where the bug is …If any one can help …