Skip to content

Commit 4b69e9e

Browse files
refactor(algorithms, intervals, employee_free_time): input validation
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent c6c6442 commit 4b69e9e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

algorithms/intervals/employee_free_time/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ def employee_free_time_heap(schedules: List[List[Interval]]) -> List[Interval]:
7070
# and add start of each schedule's first interval along with
7171
# its index value and a value 0.
7272
for i in range(len(schedules)):
73-
heap.append((schedules[i][0].start, i, 0))
73+
if schedules[i]: # Only add if employee has at least one interval
74+
heap.append((schedules[i][0].start, i, 0))
7475

7576
# Create heap from array elements.
7677
heapq.heapify(heap)
7778

79+
# Handle empty heap
80+
if not heap:
81+
return []
82+
7883
# Take an empty array to store results.
7984
free_time_slots = []
8085

0 commit comments

Comments
 (0)