GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tech-code-interview/meeting_rooms_2.py at master · BarthJr/tech-code-interview

Expand file tree

/

meeting_rooms_2.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (26 loc) · 913 Bytes
/

meeting_rooms_2.py

Copy path

File metadata and controls

34 lines (26 loc) · 913 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# https://www.lintcode.com/problem/meeting-rooms-ii/description
# Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei),
# find the minimum number of conference rooms required.
"""
>>> minMeetingRooms([Interval(5, 10), Interval(15, 20), Interval(0, 30)])
2
>>> minMeetingRooms([Interval(7, 10), Interval(2, 4)])
1
"""
import heapq
class Interval:
def __init__(self, start=0, end=0):
self.start = start
self.end = end
def minMeetingRooms(intervals):
if not intervals:
return 0
intervals.sort(key=lambda interval: interval.start)
first_interval = intervals[0]
min_heap = [first_interval.end]
for i in range(1, len(intervals)):
current = intervals[i]
if current.start >= min_heap[0]:
heapq.heappop(min_heap)
heapq.heappush(min_heap, current.end)
return len(min_heap)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.