Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-213

Priority Event Queue Ordering

Problem

Order simulated events by time and priority.

events is a list of [time, priority, id] triples. Sort by time ascending, then by priority ascending (a smaller number is more urgent), and finally by id ascending so ties are deterministic.

Return the list of ids in processing order.

Hint

The tuple (time, priority, id) provides a total, deterministic order.

Test cases

case 1
in: [[[5,1,"a"],[1,3,"b"],[1,1,"c"],[5,0,"d"]]]
expected: ["c","b","d","a"]
case 2
in: [[[2,0,"x"],[1,0,"y"]]]
expected: ["y","x"]
case 3
in: [[[1,2,"a"],[1,2,"b"]]]
expected: ["a","b"]
case 4
in: [[]]
expected: []
case 5
in: [[[3,5,"z"]]]
expected: ["z"]
Starter codePython
def event_order(events):
    # Your code here
    pass

5 test cases · run your code against them in the editor