[Solution] Distinct Neighbours CodeChef Solution
Problem
You are given an array of length .
You also have an empty array . You are asked to do the following operation exactly times.
- Choose two distinct indices and ;
- Append to the end of array ;
- Delete the and elements from and concatenate remaining elements without changing the order.
Find whether there exists a set of operations to get array such that .
Input Format
- The first line of input contains a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains an integer .
- The second line of each test case contains space-separated integers representing the array .
Output Format
For each test case, print on a new line the answer: YES
if it is possible to obtain valid , and NO
otherwise.
Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes
, YES,
yes,
yEs` will all be treated as identical.
Explanation:
Test case : No matter how we perform the operations, .
Test case :
- In first operation, we can take and . Now we append at the back of , and delete and from . Now .
- In second operation, we can take and ; append at the back of and delete and . Thus, and .
- In the third operation, we take and ; append at the back of and delete and . Thus, and .
Thus, finally . There are no two consecutive elements in that are equal.
Test case :
- In first operation, we can take and . Now we append at the back of , and delete and from . Now .
- In second operation, we can take and ; append at the back of and delete and . Thus, and .
Thus, finally . There are no two consecutive elements in that are equal.
No comments:
Post a Comment