How to solve this coding question?

Operation any number of times →

  • Choose an index i(1<=i<=n-1)
  • Increase A[i] and A[i+1] by 1

Check if array is good or bad if every element of that array has the same parity. i.e, all element of array will be either even or odd.

Print “YES” or “NO” if array can be converted to good array or not after performing operations any number of time.


Sample Input
2(No. of itmes)
3(Size of array)
3 2 3
2(Size of array)
5 2

Sample Output

Test case 1: Given array [3, 2, 3]

  • Select i=2, array [3, 3, 4]
  • Select i=1, array [4, 4, 4]
  • Now all elements of array is even, there is a good array.
    Test Case 2: it is impossible.

Check the following greedy solution.