knightnemo commited on
Commit
e9bec60
·
verified ·
1 Parent(s): 226d0aa

Upload code_segments/segment_209.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_209.txt +27 -0
code_segments/segment_209.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ In Berland, a bus consists of a row of $n$ seats numbered from $1$ to $n$. Passengers are advised to always board the bus following these rules:
2
+
3
+ * If there are no occupied seats in the bus, a passenger can sit in any free seat; * Otherwise, a passenger should sit in any free seat that has at least one occupied neighboring seat. In other words, a passenger can sit in a seat with index $i$ ($1 \le i \le n$) only if at least one of the seats with indices $i-1$ or $i+1$ is occupied.
4
+
5
+ Today, $n$ passengers boarded the bus. The array $a$ chronologically records the seat numbers they occupied. That is, $a_1$ contains the seat number where the first passenger sat, $a_2$ — the seat number where the second passenger sat, and so on.
6
+
7
+ You know the contents of the array $a$. Determine whether all passengers followed the recommendations.
8
+
9
+ For example, if $n = 5$, and $a$ = [$5, 4, 2, 1, 3$], then the recommendations were not followed, as the $3$-rd passenger sat in seat number $2$, while the neighboring seats with numbers $1$ and $3$ were free.
10
+
11
+ The first line of input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
12
+
13
+ The following describes the input test cases.
14
+
15
+ The first line of each test case contains exactly one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of seats in the bus and the number of passengers who boarded the bus.
16
+
17
+ The second line of each test case contains $n$ distinct integers $a_i$ ($1 \le a_i \le n$) — the seats that the passengers occupied in chronological order.
18
+
19
+ It is guaranteed that the sum of $n$ values across all test cases does not exceed $2 \cdot 10^5$, and that no passenger sits in an already occupied seat.
20
+
21
+ For each test case, output on a separate line:
22
+
23
+ * "YES", if all passengers followed the recommendations; * "NO" otherwise.
24
+
25
+ You may output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
26
+
27
+ The first test case is explained in the problem statement.