Skip to content

Instantly share code, notes, and snippets.

@boompig
Created November 24, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boompig/744df3b2f5c4ef49ecbe to your computer and use it in GitHub Desktop.
Save boompig/744df3b2f5c4ef49ecbe to your computer and use it in GitHub Desktop.
class Item(object):
def __init__(self, time, val):
self.time = time
self.val = val
def get_over_limit_simul(interval_list, limit):
queue = Queue(lambda o: o.time)
for interval in interval_list:
o_in = Item(interval.start, interval.val)
o_out = Item(interval.end, -1 * interval.val)
queue.push(o_in)
queue.push(o_out)
cap = 0
while len(queue) > 0:
item = queue.pop()
cap += item.val
if cap > limit:
return False
assert(cap >= 0)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment