Record So Far
Imagine a leaderboard where after each new number you want to know the best result reached so far. The function cumulative_max receives a list of numbers nums and returns a list where each element shows the largest number among all previous elements and the current one. If the input list is empty, return an empty list.
Примеры
Ввод
[1, 3, 2, 5, 4]Вывод
[1, 3, 3, 5, 5]Ввод
[]Вывод
[]Ввод
[5, 4, 3]Вывод
[5, 5, 5]Нужно реализовать
def cumulative_max(nums: list[int]) -> list[int]:
Теги
lists
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
[1,3,2,5,4]Expected
[1,3,3,5,5]2
Input
[]Expected
[]3
Input
[5,4,3]Expected
[5,5,5]4
Input
[1,2,3]Expected
[1,2,3]5
Input
[-2,-5,-1]Expected
[-2,-2,-1]6
Input
[1,3,2,5,4,1,3]Expected
[1,3,3,5,5,5,5]Focus radio
Paused · SomaFM · Fluid