Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My first reduce solution in Clear category for Internet Plan by igharok
from functools import reduce
def internet_quota(limit: int, used: list[int]) -> int:
return reduce(lambda reminder, spent: max(0, reminder + limit - spent), used, limit)
print("Example:")
print(internet_quota(200, [150, 220]))
# These "asserts" are used for self-checking
assert internet_quota(200, [150, 220]) == 230
assert internet_quota(100, [50, 80, 30]) == 240
assert internet_quota(150, [120]) == 180
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 24, 2024
Comments: