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
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónVisible tests
1
Input
[6,2,1,8,10]Expected
162
Input
[1,1,11,2,3]Expected
63
Input
[]Expected
04
Input
[3]Expected
05
Input
[-6,-20,-1,-10,-12]Expected
-286
Input
[-6,-20]Expected
0Focus radio
Paused · SomaFM · Fluid