![]() |
VOOZH | about |
Given an array arr[] of size N, the task is to find the minimum increments by 1 required to be performed on the array elements such that the count of even and odd integers in the given array becomes equal. If it is not possible, then print "-1".
Examples:
Input: arr[] = {1, 3, 4, 9}
Output: 1
Explanation:
Count of even and odd integers in the array are 1 and 3 respectively.
Increment arr[3] ( = 9) by 1 to make it 10(even).
So, as the count of even and odd integer are the same after the above steps. Hence, the minimum increment operations is 1.Input: arr[] = {2, 2, 2, 2}
Output: 2
Approach: The idea to solve the given problem is as follows:
Below is the implementation of the above approach:
1
Time Complexity: O(N)
Auxiliary Space: O(1)