[Solution] Chef and Array CodeChef Solution | Solution CodeChef
Problem
Chef has an array consisting of elements. Chef also has empty arrays and .
Chef performs the following algorithm on the arrays:
- Step : While array is not empty, Chef removes the last element of and places it in the middle of array . If currently has odd length, Chef can place the element from to the left or to the right of the middle element of . As a result, array becomes empty and now consists of elements.
- Step : While array is not empty, Chef removes the last element of and places it in the middle of array . If currently has odd length, Chef can place the element from to the left or to the right of the middle element of . As a result, array becomes empty and now consists of elements.
Determine whether he can make array sorted in non-decreasing order. Formally, determine whether he can generate the array such that for each .
Input Format
- The first line contains an integer , the number of test cases.
- Then the test cases follow. The first line of each test case contains a single integer - the length of the array .
- The second line contains space-separated integers, the elements of the array .
👇👇👇👇👇
Output Format
For each test case, output YES if you can make array sorted in non-decreasing order, otherwise, print NO.
You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical).
Explanation:
Test case : We can do the following for :
- Step : .
- Step : .
As a result, array and it is sorted.
Test case : We cannot generate array in sorted order.
No comments:
Post a Comment