Given an array **arr[]** containing **N** integers, the task is to find whether all the elements of the given array can be made 0 by following operations:

- Increment any element by 2.
- Subtract the minimum element of the array from all elements in the array.
- The above operations can be performed any number times.

If all the elements of the given array can become zero then print **Yes** else print **No**.

**Examples:**

Input:arr[] = {1, 1, 3}

Output:Yes

Explanation:

1st round: Choose the first element in the array and increase it by 2 i.e arr[] = {3, 1, 3}.

Then decrease all the elements by 1(which is minimum in the current array) i.e arr[] = {2, 0, 2}.

2nd round: Choose the second element in the array and increase it by 2 i.e arr[] = {2, 2, 2}.

Then decrease all the elements by 2(which is minimum in the current array) i.e arr[] = {0, 0, 0}.

Therefore, with the given operations performing on the elements of the array, all the elements of the given array can be reduced to 0.

Input:arr[] = {2, 1, 4, 2}

Output:No

Explanation:

We cannot make all the element of the array 0 by performing the given operations.

**Approach:** The problem can be solved with the help of Parity.

- Since, by incrementing the element of the array by 2 in each operation, the parity of the element is not changed i.e.,
**odd remains odd or even remains even**. - And after subtracting each element of the array with the minimum element in the array, the
**parity of even integers becomes odd and the parity of odd integers becomes even**. - Therefore to make all the elements of the array 0, the parity of all the elements must be same otherwise we can’t make all the elements of the array 0 by the given operations.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to whether the array ` `// can be made zero or not ` `bool` `check(` `int` `arr[], ` `int` `N) ` `{ ` ` ` `// Count for even elements ` ` ` `int` `even = 0; ` ` ` ` ` `// Count for odd elements ` ` ` `int` `odd = 0; ` ` ` ` ` `// Traverse the array to ` ` ` `// count the even and odd ` ` ` `for` `(` `int` `i = 0; i < N; i++) { ` ` ` ` ` `// If arr[i] is odd ` ` ` `if` `(arr[i] & 1) { ` ` ` `odd++; ` ` ` `} ` ` ` ` ` `// If arr[i] is even ` ` ` `else` `{ ` ` ` `even++; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Check if count of even ` ` ` `// is zero or count of odd ` ` ` `// is zero ` ` ` `if` `(even == N || odd == N) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` `} ` ` ` `// Driver's Code ` `int` `main() ` `{ ` ` ` `int` `arr[] = { 1, 1, 3 }; ` ` ` `int` `N = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` ` ` `check(arr, N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `import` `java.util.*; ` ` ` `class` `GFG{ ` ` ` `// Function to whether the array ` `// can be made zero or not ` `static` `void` `check(` `int` `arr[], ` `int` `N) ` `{ ` ` ` `// Count for even elements ` ` ` `int` `even = ` `0` `; ` ` ` ` ` `// Count for odd elements ` ` ` `int` `odd = ` `0` `; ` ` ` ` ` `// Traverse the array to ` ` ` `// count the even and odd ` ` ` `for` `(` `int` `i = ` `0` `; i < N; i++) { ` ` ` ` ` `// If arr[i] is odd ` ` ` `if` `(arr[i] % ` `2` `== ` `1` `) { ` ` ` `odd++; ` ` ` `} ` ` ` ` ` `// If arr[i] is even ` ` ` `else` `{ ` ` ` `even++; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Check if count of even ` ` ` `// is zero or count of odd ` ` ` `// is zero ` ` ` `if` `(even == N || odd == N) ` ` ` `System.out.print(` `"Yes"` `); ` ` ` `else` ` ` `System.out.print(` `"No"` `); ` `} ` ` ` `// Driver's Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `arr[] = { ` `1` `, ` `1` `, ` `3` `}; ` ` ` `int` `N = arr.length; ` ` ` ` ` `check(arr, N); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to whether the array ` `# can be made zero or not ` `def` `check(arr, N): ` ` ` ` ` `# Count for even elements ` ` ` `even ` `=` `0` `; ` ` ` ` ` `# Count for odd elements ` ` ` `odd ` `=` `0` `; ` ` ` ` ` `# Traverse the array to ` ` ` `# count the even and odd ` ` ` `for` `i ` `in` `range` `(N): ` ` ` ` ` `# If arr[i] is odd ` ` ` `if` `(arr[i] ` `%` `2` `=` `=` `1` `): ` ` ` `odd ` `+` `=` `1` `; ` ` ` ` ` `# If arr[i] is even ` ` ` `else` `: ` ` ` `even ` `+` `=` `1` `; ` ` ` ` ` `# Check if count of even ` ` ` `# is zero or count of odd ` ` ` `# is zero ` ` ` `if` `(even ` `=` `=` `N ` `or` `odd ` `=` `=` `N): ` ` ` `print` `(` `"Yes"` `); ` ` ` `else` `: ` ` ` `print` `(` `"No"` `); ` ` ` `# Driver's Code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` `arr ` `=` `[ ` `1` `, ` `1` `, ` `3` `]; ` ` ` `N ` `=` `len` `(arr); ` ` ` ` ` `check(arr, N); ` ` ` `# This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `// Function to whether the array ` `// can be made zero or not ` `static` `void` `check(` `int` `[]arr, ` `int` `N) ` `{ ` ` ` `// Count for even elements ` ` ` `int` `even = 0; ` ` ` ` ` `// Count for odd elements ` ` ` `int` `odd = 0; ` ` ` ` ` `// Traverse the array to ` ` ` `// count the even and odd ` ` ` `for` `(` `int` `i = 0; i < N; i++) { ` ` ` ` ` `// If arr[i] is odd ` ` ` `if` `(arr[i] % 2 == 1) { ` ` ` `odd++; ` ` ` `} ` ` ` ` ` `// If arr[i] is even ` ` ` `else` `{ ` ` ` `even++; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Check if count of even ` ` ` `// is zero or count of odd ` ` ` `// is zero ` ` ` `if` `(even == N || odd == N) ` ` ` `Console.Write(` `"Yes"` `); ` ` ` `else` ` ` `Console.Write(` `"No"` `); ` `} ` ` ` `// Driver's Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `[]arr = { 1, 1, 3 }; ` ` ` `int` `N = arr.Length; ` ` ` ` ` `check(arr, N); ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

Yes

**Time Complexity:** **O(N)**, where N is the length of the given array.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Check if the given array can be reduced to zeros with the given operation performed given number of times
- Check if X and Y can be made zero by using given operation any number of times
- Check if array sum can be made K by three operations on it
- Check if two arrays can be made equal by reversing subarrays multiple times
- Queries to check whether all the elements can be made positive by flipping signs exactly K times
- Check if all elements of binary array can be made 1
- Check if all elements of the given array can be made 0 by decrementing value in pairs
- Check whether an Array can be made 0 by splitting and merging repeatedly
- Check whether the number can be made palindromic after adding K
- Check whether an array can be made strictly decreasing by modifying at most one element
- Check whether the number can be made perfect square after adding K
- Check whether the number can be made perfect square after adding 1
- Check whether an array can be made strictly increasing by modifying atmost one element
- Check if elements of array can be made equal by multiplying given prime numbers
- Check if an Array is made up of Subarrays of continuous repetitions of every distinct element
- Check whether K times of a element is present in array
- Check if original Array is retained after performing XOR with M exactly K times
- Check if the last element of array is even or odd after performing a operation p times
- Check if its possible to make sum of the array odd with given Operations
- Queries to check whether all the elements in the given range occurs even number of times

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.