Does it make sense to use a dict here? On line 341 you are keeping track of the biggest interval with an index, it will be easier to read if it is a key.