Fair and Balanced

Let’s consider an array "balanced" if the sum of the elements on the left half of the array is equal to the sum of the elements on the right half of the array. In an array with an odd number of elements, we ignore the element in the middle when making that determination. For example,

int a[] = {17, 40, 28, 29};

is balanced, because the sum of its left half is 17 + 40 = 57, just as the sum of its right half is 28 + 29 = 57. Similarly,

int b[] = {30, 22, 11, -14, 66};

is balanced, because the sum of its left half is 30 + 22 = 52, just as the sum of its right half is -14 + 66 = 52; we ignore its middle element (11) altogether.

Answer the below in balanced.md.

Questions

  1. (1 point.) Is the array {16, 26, 39, 3, 39} balanced?

  2. (1 point.) Is the array {0, 0, 0, 0, 0} balanced?

  3. (4 points.) Implement a function called balanced that accepts two parameters: an array of integers, array, and an integer, n, that represents the length of array. The function should return true if array is balanced and false otherwise. Assume that n is positive.

Debrief

  1. Which resources, if any, did you find helpful in answering this problem’s questions?

  2. About how long did you spend on this problem’s questions?