Skip to content

ORIGINAL CODING QUESTION

Balanced sprint pivot

Sprint story points are listed in order. Find the smallest zero-based index p such that the total of the points strictly before p equals the total strictly after p. An empty side totals 0. Return -1 if no such index exists.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

First integer n, then n integers. Print one integer.

Constraints

1 ≤ n ≤ 200; -1000 ≤ points ≤ 1000.

Example 1

Input

6
1 7 3 6 5 6

Output

3

At index 3, the left side 1+7+3 and the right side 5+6 both total 11.

Example 2

Input

3
1 2 3

Output

-1

No index balances the two sides.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Recomputing both sides for every index works but repeats a lot of addition.

Hint 2

If you know the grand total and the running total to the left, the right side follows.

Hint 3

Walk left to right keeping leftSum; at index i the right side is total - leftSum - value[i]; return the first i where the two match.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →