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
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięVisible tests
1
Input
[-7,1,5,2,-4,3,0]Expected
32
Input
[1,2,3,4,5]Expected
-13
Input
[1,1,1,1,1]Expected
24
Input
[2,4,6,8,10,3]Expected
-15
Input
[1,2,3,4,5,1]Expected
36
Input
[-6,2,6,3,-3,4,1]Expected
3Focus radio
Paused · SomaFM · Fluid