Adjacent Parity
Practice
3.2 (6 votes)
Linear search
Algorithms
Greedy algorithm
Problem
61% Success 1319 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array A containing N integers. Find if it is possible to rearrange the elements of the array such that the parity of the sum of each pair of adjacent elements is equal (formally, \(parity(A_i + A_{i+1}) = parity(A_{j} + A_{j+1})\) for each \(1 \leq i \lt j \leq N-1\) ).
Here, parity refers to the remainder obtained when a number is divided by 2 (i.e. \(parity(x) = x \mod 2\)).
Input format
- The first line contains T denoting the number of test cases. The description of T test cases is as follows:
- For each test case:
- The first line contains N denoting the size of array A.
- The second line contains N space-separated integers A[1], A[2], ....., A[N] - denoting the elements of A.
Output format
For each test case, print "YES"(without quotes) if it is possible to reorder the array elements to satisfy the given condition and "NO"(without quotes) otherwise.
Constraints
\(1 \leq T \leq 100 \\ 1 \leq N \leq 100\\ 1 \le A_i \le 100\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
195 votes
Tags:
AlgorithmsEasySearching
2.Find Mex
Points:10
16 votes
Tags:
AlgorithmsBrute ForceImplementationLinear SearchIterators
Points:10
66 votes
Tags:
AlgorithmsBrute ForceC++Searching
Editorial