Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Speedy category for Lightbulb End Watching by Alex_4444D
from datetime import datetime
from typing import List, Optional
def sum_light(els: List[datetime], start_watching: Optional[datetime] = None, end_watching: Optional[datetime] = None) -> int:
if not(end_watching) : end_watching = datetime(9999, 12, 31, 23, 59, 59)
if not(start_watching) : start_watching = datetime(1900, 1, 12, 10, 0, 0)
if len(els) %2 != 0: els.append(end_watching)
return sum([(min(pair[1],end_watching)- max(pair[0],start_watching)).total_seconds() if not(pair[0]>=end_watching or pair[1]<=start_watching) else 0 for pair in zip(els[::2],els[1::2])])
Nov. 6, 2021
Comments: