Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code Written by : John Nixon
- // Date: 09:11:2022 Time: 21:53:46
- // Copyrights are applicable
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define vi vector<int>
- #define vll vector<long long int>
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- std::ios::sync_with_stdio(false);
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- if (n <= 2)
- {
- cout << "YES" << endl;
- }
- else if (a[0] == a[n - 1])
- {
- cout << "YES" << endl;
- }
- else
- {
- bool flag = false;
- for (int i = 0; i < n - 1; i++)
- {
- if (a[i] == a[0] && a[i + 1] == a[n - 1])
- {
- flag = true;
- break;
- }
- }
- if (flag)
- {
- cout << "YES" << endl;
- }
- else
- {
- cout << "NO" << endl;
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement