VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimize-increments-required-to-make-count-of-even-and-odd-array-elements-equal/

⇱ Minimize increments required to make count of even and odd array elements equal - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimize increments required to make count of even and odd array elements equal

Last Updated : 23 Jul, 2025

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:

  • If N is even, then traverse the array and keep a count of odd and even integers. The absolute difference of the count of even and odd integers divided by 2 gives the minimum increment operations required to make even and odd numbers equal.
  • If N is odd, then it is not possible to make even and odd numbers equal, hence print "-1".

Below is the implementation of the above approach:


Output: 
1

 

Time Complexity: O(N)
Auxiliary Space: O(1)

Comment