Balanced Index

Imagine a row of numbers like a balance scale: one sum on the left, another on the right. Given a list arr, return the first index where the sum of all elements to the left equals the sum of all elements to the right. The element at that index is not included in either sum. If no such index exists, return -1.

Примеры

Ввод
[-7, 1, 5, 2, -4, 3, 0]
Вывод
3
Ввод
[1, 2, 3, 4, 5]
Вывод
-1
Ввод
[1, 1, 1, 1, 1]
Вывод
2

Нужно реализовать

def equilibrium_index(arr: list[int]) -> int:

Теги

array
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Visible tests
1
Input
[-7,1,5,2,-4,3,0]
Expected3
2
Input
[1,2,3,4,5]
Expected-1
3
Input
[1,1,1,1,1]
Expected2
4
Input
[2,4,6,8,10,3]
Expected-1
5
Input
[1,2,3,4,5,1]
Expected3
6
Input
[-6,2,6,3,-3,4,1]
Expected3
Focus radio
Paused · SomaFM · Fluid