Advertisement
jbn6972

Untitled

Nov 9th, 2022
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. // Code Written by : John Nixon
  2. // Date: 09:11:2022  Time: 21:53:46
  3. // Copyrights are applicable
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. #define ll long long
  7. #define vi vector<int>
  8. #define vll vector<long long int>
  9. int main()
  10. {
  11. #ifndef ONLINE_JUDGE
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14. #endif
  15.     std::ios::sync_with_stdio(false);
  16.     int t;
  17.     cin >> t;
  18.     while (t--)
  19.     {
  20.         int n;
  21.         cin >> n;
  22.         vector<int> a(n);
  23.  
  24.         for (int i = 0; i < n; i++)
  25.         {
  26.             cin >> a[i];
  27.         }
  28.         if (n <= 2)
  29.         {
  30.             cout << "YES" << endl;
  31.         }
  32.         else if (a[0] == a[n - 1])
  33.         {
  34.             cout << "YES" << endl;
  35.         }
  36.         else
  37.         {
  38.             bool flag = false;
  39.             for (int i = 0; i < n - 1; i++)
  40.             {
  41.                 if (a[i] == a[0] && a[i + 1] == a[n - 1])
  42.                 {
  43.                     flag = true;
  44.                     break;
  45.                 }
  46.             }
  47.             if (flag)
  48.             {
  49.                 cout << "YES" << endl;
  50.             }
  51.             else
  52.             {
  53.                 cout << "NO" << endl;
  54.             }
  55.         }
  56.     }
  57.     return;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement