Question: A balanced array is defined to be an array where for every value n in the array, -n also is in the array. For example

A balanced array is defined to be an array where for every value n in the array, -n also is in the array. For example {-2, 3, 2, -3} is a balanced array. So is {-2, 2, 2, 2}. But {-5, 2, -2} is not because 5 is not in the array.

 

Write a function named isBalanced that returns 1 if its array argument is a balanced array. Otherwise it returns 0.

 

If you are programming in Java or C#, the function signature is

int isBalanced (int [ ] a);

If you are programming in C or C++, the function signature is

int isBalanced(int a[ ], int len) where len is the number of elements in the array.

 

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Below is the implementation of the isBalanced function in C The function checks whether th... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!