SCHEDULE_STRING = "Mon 01:00 - 23:00\nTue 01:00 - 23:00\nWed 01:00 - 23:00\nThu 01:00 - 23:00\nFri 01:00 - 23:00\nSat 01:00 - 23:00\nSun 01:00 - 21:00\n" ONE_HOUR_IN_MINUTES = 60 def solution(s): longest_time = 0 schedule_parts = [schedule for schedule in s.split("\n") if schedule != ''] for schedule in schedule_parts: (day, allowance) = get_finish_time(schedule) if allowance > longest_time: longest_time = allowance return (day, to_minutes(longest_time)) def get_finish_time(schedule): end_of_day = 24.00 [day_and_start, finish] = schedule.split('-') day = day_and_start.split(' ')[0] float_finish_time = float(finish.strip().replace(':', '.')) time_diff = end_of_day - float_finish_time a = (day, time_diff) return a def to_minutes(hour): return hour * ONE_HOUR_IN_MINUTES print(solution(SCHEDULE_STRING)) #TODO # take care of the other case of 55x minutes in case of fractions of hours