#K41832. Find the Balance Point in an Array
Find the Balance Point in an Array
Find the Balance Point in an Array
You are given a list of integers. Your task is to find the balance point in the list.
A balance point is an index i such that the sum of all elements to the left of i is equal to the sum of all elements to its right. Formally, find an index i (0-indexed) such that
\(\sum_{j=0}^{i-1} a_j = \sum_{j=i+1}^{n-1} a_j\)
If such an index exists, output it. Otherwise, output \(-1\). Note that if the list is empty, the answer is \(-1\), and if the list contains a single element, the answer is \(0\) since the sums on both sides are \(0\).
inputFormat
The first line of the input contains a single integer \(n\) representing the number of elements in the list.
If \(n > 0\), the second line contains \(n\) space-separated integers representing the list.
outputFormat
Output a single integer representing the balance point index. If no balance point exists, output \(-1\).
## sample7
1 2 3 4 3 2 1
3
</p>