Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Index-based, should have use range() solution in Clear category for Lightbulb Intro by kkkkk
from datetime import datetime
from typing import List
def sum_light(els: List[datetime]) -> int:
"""Return the time in seconds that the light bulb has been turned on."""
total_duration = 0
for idx, switch_flipped in enumerate(els):
if idx % 2:
duration = switch_flipped - els[idx - 1]
total_duration += duration.total_seconds()
return int(total_duration)
Jan. 17, 2022
Comments: