➤ Problem Link : 1324B. Yet Another Palindrome Problem
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { int t; cin>>t; while(t--) { int n; cin>>n; if(n<3) { cout<<"NO\n"; continue; } int arr[n]; unordered_map<int,int> mp; mp.clear(); bool flag=0; for(int i=0;i<n;i++) { cin>>arr[i]; } for(int i=0;i<n;i++) { if(mp.find(arr[i])==mp.end()) mp[arr[i]]=i; else if( i > mp[arr[i]]+1) { flag=1; break; } } if(flag) cout<<"YES\n"; else cout<<"NO\n"; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!