# Karat course times

unknown
python
2 years ago
2.3 kB
5
Indexable
Never
```"""
generate map of name -> list of times
for name, times in map:
sorted_times = sort times by asc order
temp = [sorted_times[0]]
for i, curr_end in sorted_times[1:]:
if diff < 60:
else if len(temp) > 1:  # already have an interval
break
else: # reset interval
temp = [curr_end]

if len(temp) > 1:

return res
"""

def solve(pairs: List[List[str]]) -> Dict[str, List[str]]:
name_times_map = {}
for name, time in pairs:
if name not in name_times_map:
name_times_map[name] = []
name_times_map[name].append(time)

name_intervals_map = {}
for name, times in name_times_map.items():
sorted_times = sorted(times)
curr_interval = [sorted_times[0]]
for curr_end_idx in range(1, len(sorted_times)):
curr_end = sorted_times[curr_end_idx]

if time_diff < 60:
curr_interval.append(curr_end)
elif len(curr_interval) > 1:
break
else:
curr_interval = [curr_end]

if len(curr_interval) > 1:
name_intervals_map[name] = curr_interval
return name_intervals_map

def time_diff_in_mins(x: str, y: str) -> float:
x = int(x)
y = int(y)
hour_x = int(x / 100)
hour_y = int(y / 100)
min_x = x % 100
min_y = y % 100
return (hour_x * 60 + min_x) - (hour_y * 60 + min_y)

testcase1 = [["James", "1300"], ["Martha", "1600"], ["Martha", "1620"], ["Martha", "1530"]]
testcase2 = [["James", "1300"], ["James", "1330"], ["Martha", "1600"], ["Martha", "1620"], ["Martha", "1400"]]
testcase3 = [["James", "1300"], ["Martha", "1600"], ["Martha", "1630"], ["Martha", "1800"], ["Martha", "1830"]]

assert solve(testcase1) == {'Martha': ['1530', '1600', '1620']}
assert solve(testcase2) == {'James': ['1300', '1330'], 'Martha': ['1600', '1620']}
assert solve(testcase3) == {'Martha': ['1600', '1630']}
```