brute force strings *1100

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, l, k = int(input()), list(map(int, input().split())), False
    for i in range(n):
        if l[i:].count(l[i]) == 2:
            if l[i+1] != l[i]:
                print("YES")
                k = True
                break
        elif l.count(l[i]) > 2:
            print("YES")
            k = True
            break
    if k == False:
        print("NO")

C++ Code:

// Problem: B. Yet Another Palindrome Problem
// Contest: Codeforces - Codeforces Round #627 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1324/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms

/* 
     
     #WTFyouhere
                    ♕ABHINAV♕
     
        HUSTLE KARO BHASAD NHI..... 
          
                             
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const unsigned int M = 1000000007;
//►►►►►►►►►►►►►►►►►►►►(⊙⊙)(☉_☉)(⊙⊙)►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►
ll power(ll a, ll b, ll m = M) {a %= m;ll res = 1;while (b > 0) {
if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
ll gcd(ll x, ll y) {return (x ? gcd(y % x, x) : y);}
ll inv(ll n, ll m = M) {return power(n, m - 2, m);}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
ll nextgreaterelement(ll n) {auto digits = to_string(n);
next_permutation(begin(digits), end(digits));auto res = stoll(digits);return res;}
vector<int> factorize(int n) {vector<int> ans;for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {ans.push_back(i);n /= i;}}if (n != 1) {ans.push_back(n);}
for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";}
ll near_pow(ll q){ll ans = (ll)log2(q);return pow(2,ans);}
long long ceil(long long p, long long q) {if(p % q == 0) return (p / q);return (p / q) + 1;}
//►►►►►►►►►►►►►►►►►►►(⊙⊙)(☉_☉)(⊙⊙)►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►►


void reply()
{
    ll t;
    cin>>t;
    while(t--)
    {
         int n;
         cin>>n;
         int a[n];
         for(int i=1;i<=n;i++)
         {
         	cin>>a[i];
         }
         bool flag=0;
         for(int i=1;i<=n;i++)
         {
         	for(int j=i+2;j<=n;j++)
         	{
         		if(a[i]==a[j])
         		{
         			flag=1;
         			break;
         		}
         	}
         }
         if(flag)cout<<"YES"<<endl;
         else cout<<"NO"<<endl;                
                              
    }
    
}


int main() {
	// your code goes here
	reply();
	
	
	
}


Comments

Submit
0 Comments
More Questions

1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String
216A - Tiling with Hexagons
1351B - Square
1225A - Forgetting Things
1717A - Madoka and Strange Thoughts
1717B - Madoka and Underground Competitions
61B - Hard Work
959B - Mahmoud and Ehab and the message
802G - Fake News (easy)
1717C - Madoka and Formal Statement
420A - Start Up
1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban
1585C - Minimize Distance
1506E - Restoring the Permutation
1539A - Contest Start
363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys