[Solution] Yet Another Palindrome Problem CodeChef Solution
Problem
Chef has an array of size . He can perform the following operation on :
- Select an and for all , set (i.e. add to every element in the prefix of length ).
Chef wants to convert to a palindrome by using the above operation minimum number of times. Can you help Chef?
If it is not possible to convert to a palindrome, output .
Note: An array is called palindrome if it reads the same backwards and forwards, for e.g. and are palindromic arrays.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the array .
- The second line of each test case contains space-separated integers denoting the array .
Output Format
For each test case, output the minimum number of operations required to convert to a palindromic array.
If it is not possible to do so, output .
Explanation:
Test case : The given array is already a palindrome.
Test case : It can be proven that it is not possible to convert to a palindromic array using the given operation.
Test case : We can perform the following operations:
- Select ,
- Select ,
- Select ,
No comments:
Post a Comment