JPMorgan ChaseOA #4
Balanced Sum
Estimated EasyJudge-ready
Topics (AI-labelled)Prefix & Ranges
Without reordering the array, find the pivot whose left-side and right-side element sums are equal, and return its 0-based index; the pivot itself belongs to neither side. A solution is guaranteed to exist.
Input
The first line contains n, followed by n positive integers; full original bounds 3≤n≤100000, 1≤a[i]≤20000. The guarantee that a solution exists comes from the original statement.
Output
Output a single integer answer.
Example 1
Input:
5
1 2 3 4 6
Output:
3
Example 2
Input:
4
1 2 3 3
Output:
2
Example 3
Input:
3
7 1 7
Output:
1
Example notes
The outputs of the three public examples are, in order: 3; 2; 1. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…