Given a circular array **arr[] **of size** N, **the task is to check if it is possible to make all array elements of the circular array equal by increasing pairs of adjacent elements by **1**.

**Examples:**

Input:N = 4, arr[] = {2, 1, 3, 4}Output:YesExplanation:

Step 1: {2, 1, 3, 4} -> {3, 2, 3, 4}

Step 2: {3, 2, 3, 4} -> {4, 3, 3, 4}

Step 3: {4,3, 3, 4} -> {4,4, 4, 4}Input:N = 6, arr[]={1, 5, 9, 6, 1, 1}Output:No

**Approach:** To solve the problem, it can be observed that the two indices consisting of elements to be incremented, one is* even* and the other one is

*. Therefore, if we increase the value of an even-indexed element, consequently an odd-indexed element will also be increased. Therefore, all the array elements can be made equal only if the sum of odd-indexed elements and even-indexed elements are equal. Follow the steps below to solve the problem:*

**odd**- Calculate the sum of all even-indexed numbers, i.e
**sumEven**. - Calculate the sum of all odd-indexed numbers, i.e
**sumOdd**. - If
and**sumEven**are found to be equal, then print “**sumOdd****Yes**” else “**No**”.

Below is the implementation of the above approach:

## C++

`// C++ Program to implement` `// the above approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to check if all array` `// elements can be made equal` `bool` `checkEquall(` `int` `arr[], ` `int` `N)` `{` ` ` `// Stores the sum of even and` ` ` `// odd array elements` ` ` `int` `sumEven = 0, sumOdd = 0;` ` ` `for` `(` `int` `i = 0; i < N; i++) {` ` ` `// If index is odd` ` ` `if` `(i & 1)` ` ` `sumOdd += arr[i];` ` ` `else` ` ` `sumEven += arr[i];` ` ` `}` ` ` `if` `(sumEven == sumOdd)` ` ` `return` `true` `;` ` ` `else` ` ` `return` `false` `;` `}` `// Driver Code` `int` `main()` `{` ` ` `int` `arr[] = { 2, 7, 3, 5, 7 };` ` ` `int` `N = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]);` ` ` `if` `(checkEquall(arr, N))` ` ` `cout << ` `"YES"` `<< endl;` ` ` `else` ` ` `cout << ` `"NO"` `<< endl;` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program to implement` `// the above approach` `import` `java.util.*;` `class` `GFG{` `// Function to check if all array` `// elements can be made equal` `static` `boolean` `checkEquall(` `int` `arr[], ` `int` `N)` `{` ` ` ` ` `// Stores the sum of even and` ` ` `// odd array elements` ` ` `int` `sumEven = ` `0` `, sumOdd = ` `0` `;` ` ` ` ` `for` `(` `int` `i = ` `0` `; i < N; i++)` ` ` `{` ` ` ` ` `// If index is odd` ` ` `if` `(i % ` `2` `== ` `1` `)` ` ` `sumOdd += arr[i];` ` ` `else` ` ` `sumEven += arr[i];` ` ` `}` ` ` `if` `(sumEven == sumOdd)` ` ` `return` `true` `;` ` ` `else` ` ` `return` `false` `;` `}` `// Driver Code` `public` `static` `void` `main(String[] args)` `{` ` ` `int` `arr[] = { ` `2` `, ` `7` `, ` `3` `, ` `5` `, ` `7` `};` ` ` `int` `N = arr.length;` ` ` ` ` `if` `(checkEquall(arr, N))` ` ` `System.out.print(` `"YES"` `+ ` `"\n"` `);` ` ` `else` ` ` `System.out.print(` `"NO"` `+ ` `"\n"` `);` `}` `}` `// This code is contributed by PrinciRaj1992` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to implement` `# the above approach` `# Function to check if all array` `# elements can be made equal` `def` `checkEquall(arr, N):` ` ` `# Stores the sum of even and` ` ` `# odd array elements` ` ` `sumEven, sumOdd ` `=` `0` `, ` `0` ` ` ` ` `for` `i ` `in` `range` `(N):` ` ` `# If index is odd` ` ` `if` `(i & ` `1` `):` ` ` `sumOdd ` `+` `=` `arr[i]` ` ` `else` `:` ` ` `sumEven ` `+` `=` `arr[i]` ` ` ` ` `if` `(sumEven ` `=` `=` `sumOdd):` ` ` `return` `True` ` ` `else` `:` ` ` `return` `False` `# Driver Code` `if` `__name__ ` `=` `=` `"__main__"` `:` ` ` `arr ` `=` `[ ` `2` `, ` `7` `, ` `3` `, ` `5` `, ` `7` `]` ` ` `N ` `=` `len` `(arr)` ` ` ` ` `if` `(checkEquall(arr, N)):` ` ` `print` `(` `"YES"` `)` ` ` `else` `:` ` ` `print` `(` `"NO"` `)` `# This code is contributed by chitranayal` |

*chevron_right*

*filter_none*

## C#

`// C# program to implement` `// the above approach` `using` `System;` `class` `GFG{` `// Function to check if all array` `// elements can be made equal` `static` `bool` `checkEquall(` `int` `[]arr, ` `int` `N)` `{` ` ` ` ` `// Stores the sum of even and` ` ` `// odd array elements` ` ` `int` `sumEven = 0, sumOdd = 0;` ` ` ` ` `for` `(` `int` `i = 0; i < N; i++)` ` ` `{` ` ` ` ` `// If index is odd` ` ` `if` `(i % 2 == 1)` ` ` `sumOdd += arr[i];` ` ` `else` ` ` `sumEven += arr[i];` ` ` `}` ` ` `if` `(sumEven == sumOdd)` ` ` `return` `true` `;` ` ` `else` ` ` `return` `false` `;` `}` `// Driver Code` `public` `static` `void` `Main(String[] args)` `{` ` ` `int` `[]arr = { 2, 7, 3, 5, 7 };` ` ` `int` `N = arr.Length;` ` ` ` ` `if` `(checkEquall(arr, N))` ` ` `Console.Write(` `"YES"` `+ ` `"\n"` `);` ` ` `else` ` ` `Console.Write(` `"NO"` `+ ` `"\n"` `);` `}` `}` `// This code is contributed by PrinciRaj1992` |

*chevron_right*

*filter_none*

**Output:**

YES

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

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.