Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal.
Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered.
Example arr=[1,2,3,4,6]
- the sum of the first three elements, 1+2+3=6. The value of the last element is 6.
- Using zero based indexing, arr[3]=4 is the pivot between the two subarrays.
- The index of the pivot is 3.
Function Description
Complete the function balancedSum in the editor below.
balanced Sum has the following
parameter(s):
int arr(n): an array of integers
Returns:
int: an integer representing the index of the pivot
Constraints
- 3≤n≤105
- 1≤ arr[i]≤ 2 * 104, where 0≤i<n< p=””></n<>
- It is guaranteed that a solution always exists.
In: Other