If anyone has solved this question in 634 div3 contest , please tell why my code isn’t working . I have tried each and every possible input .
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int a[n];
int pref[27][n];
int suff[27][n];
memset(pref,0,sizeof(pref));
memset(suff,0,sizeof(suff));
for(int i = 0 ; i < n ; i++ ){
cin >> a[i];
}
if(n==1){
cout << "1\n";
}
else if(n==2){
if(a[0]==a[1]){
cout << "2\n";
}
else{
cout <<"1\n";
}
}
else{
for(int i = 0 ; i < n ; i++ ){
if(i==0){
pref[a[i]][i]++;
}
else{
for(int j = 1 ; j <= 26 ; j++ ){
pref[j][i]+=pref[j][i-1];
}
pref[a[i]][i]++;
}
}
for(int i = n-1 ; i>=0 ; i--){
if(i==n-1){
suff[a[i]][i]++;
}
else{
for(int j = 1 ; j <= 26 ; j++ ){
suff[j][i]+=suff[j][i+1];
}
suff[a[i]][i]++;
}
}
int ans = 1;
for(int i = 1 ; i < n-1 ; i++ ){
int c = 0;
for(int j = 1 ; j <= 26 ; j++ ){
if(j!=a[i])
c = max(c,min(pref[j][i-1],suff[j][i+1]));
}
c = c*2;
c+=pref[a[i]][i-1]+suff[a[i]][i+1]+1;
ans = max(ans,c);
}
cout << ans << "\n";
}
}
}
Thanks in advance