#K43042. Taco Pattern Construction
Taco Pattern Construction
Taco Pattern Construction
In this problem, you are given a sequence of colored beads represented as integers. The task is to determine whether the given bead pattern can be constructed following Clara's rules. In particular, each color must appear as a single contiguous block within the sequence. Formally, let (S = [s_1, s_2, \dots, s_n]) be the sequence of bead colors. The pattern is valid if for every color (c), whenever (c = s_i) for some index (i) such that either (i=1) or (s_i \neq s_{i-1}), the color (c) does not appear again later in the sequence. If a color appears in two or more disjoint blocks, the answer is NO; otherwise, it is YES.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer (T) representing the number of test cases. For each test case, the first line contains an integer (n) denoting the length of the bead sequence. The second line contains (n) space-separated integers representing the colors of the beads.
outputFormat
For each test case, output a single line containing either YES if the bead pattern can be constructed according to the rules, or NO otherwise. The output should be printed to standard output (stdout).## sample
3
6
1 1 2 2 3 3
4
1 2 1 2
5
2 2 3 3 2
YES
NO
NO
</p>