Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
second solution in Clear category for Lightbulb Start Watching by kazuki.h
from datetime import datetime
from typing import List, Optional
def sub_sum_light(els: List[datetime]) -> int:
return sum([(els[i * 2 + 1] - els[i * 2]).days * 24 * 3600 + (els[i * 2 + 1] - els[i * 2]).seconds for i in range(len(els) // 2)])
def sum_light(els: List[datetime], start_watching: Optional[datetime] = None) -> int:
start = 0
if start_watching == None:
return sub_sum_light(els)
while els[start] < start_watching:
start += 1
if start % 2 == 0:
return sub_sum_light(els[start:])
else:
return sub_sum_light([start_watching] + els[start:])
May 18, 2021