题库练习 Kalindrome Array
← 上一题 下一题 →

A14731 | Kalindrome Array

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

An array $[b_1, b_2, \ldots, b_m]$ is a palindrome, if $b_i = b_{m+1-i}$ for each $i$ from $1$ to $m$ . Empty array is also a palindrome.

An array is called kalindrome, if the following condition holds:

- It's possible to select some integer $x$ and delete some of the elements of the array equal to $x$ , so that the remaining array (after gluing together the remaining parts) is a palindrome.

Note that you don't have to delete all elements equal to $x$ , and you don't have to delete at least one element equal to $x$ .

For example :

- $[1, 2, 1]$ is kalindrome because you can simply not delete a single element.
- $[3, 1, 2, 3, 1]$ is kalindrome because you can choose $x = 3$ and delete both elements equal to $3$ , obtaining array $[1, 2, 1]$ , which is a palindrome.
- $[1, 2, 3]$ is not kalindrome.

You are given an array $[a_1, a_2, \ldots, a_n]$ . Determine if $a$ is kalindrome or not.

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the length of the array.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le n$ ) — elements of the array.

It's guaranteed that the sum of $n$ over all test cases won't exceed $2 \cdot 10^5$ .

输出格式

For each test case, print YES if $a$ is kalindrome and NO otherwise. You can print each letter in any case.

输入输出样例

输入 #1
4
1
1
2
1 2
3
1 2 3
5
1 4 4 1 4
输出 #1
YES
YES
NO
YES
C++ 编辑器
输入
输出