Sum Without Extremes

Sometimes a total is calculated after removing one highest and one lowest value so they do not distort the result. Write sum_array, which takes a list arr, excludes exactly one minimum and exactly one maximum, then adds the remaining numbers. If the list is empty or has only one element, return 0.

Примеры

Ввод
[6, 2, 1, 8, 10]
Вывод
16
Ввод
[1, 1, 11, 2, 3]
Вывод
6
Ввод
[]
Вывод
0

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

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

Теги

listsarraymathsorting
PostgreSQLv16

Aici va apărea rezultatul execuției codului

Visible tests
1
Input
[6,2,1,8,10]
Expected16
2
Input
[1,1,11,2,3]
Expected6
3
Input
[]
Expected0
4
Input
[3]
Expected0
5
Input
[-6,-20,-1,-10,-12]
Expected-28
6
Input
[-6,-20]
Expected0
Focus radio
Paused · SomaFM · Fluid