Ejemplo n.º 1
0
def find_suspects(people):
    people_inside = BST()
    # min heap (ordered by exit time)
    building = Heap(key=lambda person: person.exit)
    # list of SuspectGroups
    suspects = []
    for person in people:
        next_to_leave = building.top()
        while next_to_leave is not None and not next_to_leave.shares_time_with(
                person):
            same_time = [building.pop()]
            while building.top(
            ) is not None and next_to_leave.exits_at_same_time(building.top()):
                same_time.append(building.pop())
            append_if_are_suspects(suspects, people_inside, next_to_leave)
            for next in same_time:
                people_inside.remove(next)
            next_to_leave = building.top()
        people_inside.insert(person)
        building.push(person)

    while len(people_inside) > 4:
        next_to_leave = [building.pop()]
        while building.top(
        ) is not None and next_to_leave[0].exits_at_same_time(building.top()):
            next_to_leave.append(building.pop())
        append_if_are_suspects(suspects, people_inside, next_to_leave[0])
        for next in next_to_leave:
            people_inside.remove(next)
    return suspects