Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pop max solution in Clear category for Replace with Biggest by BootzenKatzen
from typing import Iterable
def replace_biggest(data: list[int]) -> Iterable[int]:
result = [] # create new list
if data: # if the input list isn't empty
while len(data) > 1: # loop through the list until there's only 1 item left
goodbye = data.pop(0) # remove the first element
result.append(max(data)) # add the max of the remaining elements
result.append(-1) # when all the data has been gone through, add -1
return result # return the final result (or an empty list if there was no data)
print("Example:")
print(list(replace_biggest([17, 18, 5, 4, 6, 1])))
# These "asserts" are used for self-checking
assert list(replace_biggest([17, 18, 5, 4, 6, 1])) == [18, 6, 6, 6, 1, -1]
assert list(replace_biggest([1, 2, 3, 4, 5, 6])) == [6, 6, 6, 6, 6, -1]
assert list(replace_biggest([1, 1, 1])) == [1, 1, -1]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 14, 2023
Comments: