Left and Right Balance

For each element, compare how much total value is on its left with how much is on its right. Write a function left_right_difference where, for position i, the left sum does not include nums[i], and the right sum also does not include nums[i]. Return a list where each position contains the absolute difference between the left and right sums.

Примеры

Ввод
[10, 4, 8, 3]
Вывод
[15, 1, 11, 22]
Ввод
[1]
Вывод
[0]
Ввод
[1, 2, 3]
Вывод
[5, 2, 3]

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

def left_right_difference(nums: list[int]) -> list[int]:

Теги

arraymath
PostgreSQLv16

Tukaj bo rezultat izvajanja kode

Visible tests
1
Input
[10,4,8,3]
Expected[15,1,11,22]
2
Input
[1]
Expected[0]
3
Input
[1,2,3]
Expected[5,2,3]
4
Input
[0,0,0]
Expected[0,0,0]
5
Input
[5,5]
Expected[5,5]
6
Input
[1,2,3,4,5]
Expected[14,11,6,1,10]
Focus radio
Paused · SomaFM · Fluid