Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created September 30, 2014 13:09
Show Gist options
  • Save juanplopes/a981f73deaf4068c3b52 to your computer and use it in GitHub Desktop.
Save juanplopes/a981f73deaf4068c3b52 to your computer and use it in GitHub Desktop.
Simple scheduling algorithm in python
import heapq
def schedule(tasks):
heap = []
def offer(begin, end):
while heap and heap[0] <= begin:
heapq.heappop(heap)
heapq.heappush(heap, end)
return len(heap)
return max(offer(begin, end) for begin, end in sorted(tasks))
print schedule([(12,13), (13,15), (17,20), (13,14), (19, 21), (18, 20)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment