0
0
DSA Pythonprogramming~10 mins

Meeting Rooms Problem Minimum Rooms Required in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to sort the intervals by their start time.

DSA Python
intervals.sort(key=lambda x: x[[1]])
Drag options to blanks, or click blank then click option'
A0
B[0]
C[1]
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using x[1] instead of x[0] to sort by end time.
Forgetting to use the key parameter in sort.
2fill in blank
medium

Complete the code to initialize a min-heap for tracking end times.

DSA Python
import heapq
heap = []
heapq.[1](heap, intervals[0][1])
Drag options to blanks, or click blank then click option'
Aheappush
Bpush
Cinsert
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of heappush causes AttributeError.
Using append instead of heappush breaks heap property.
3fill in blank
hard

Fix the error in the condition to check if the current meeting can reuse a room.

DSA Python
if intervals[i][0] [1] heap[0]:
Drag options to blanks, or click blank then click option'
A<=
B>
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes wrong logic and incorrect room count.
Using '<' misses the case when meetings start exactly at end time.
4fill in blank
hard

Fill both blanks to pop the earliest end time and push the current meeting's end time.

DSA Python
heapq.[1](heap)
heapq.[2](heap, intervals[i][1])
Drag options to blanks, or click blank then click option'
Aheappop
Bheappush
Cpop
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop or push instead of heappop/heappush breaks heap property.
Forgetting to pop before pushing causes incorrect room count.
5fill in blank
hard

Fill all three blanks to complete the function that returns minimum meeting rooms required.

DSA Python
def minMeetingRooms(intervals):
    if not intervals:
        return 0
    intervals.sort(key=lambda x: x[[1]])
    import heapq
    heap = []
    heapq.heappush(heap, intervals[0][1])
    for i in range(1, len(intervals)):
        if intervals[i][0] [2] heap[0]:
            heapq.heappop(heap)
        heapq.heappush(heap, intervals[i][[3]])
    return len(heap)
Drag options to blanks, or click blank then click option'
A[
B>=
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for start or end times.
Using '<=' instead of '>=' in condition.
Pushing start time instead of end time into heap.