SORT-P6

The departure board

Practice 6 of 6Sorting6 tests

The problem

Each train is a list [name, platform, time], where time is a string like "09:05". Return the names in the order the board shows them:

  • by platform, lowest first;
  • on the same platform, the latest time first;
  • trains with the same platform and time stay in their input order.
arrange_board([["Rajdhani", 3, "16:55"],
               ["Shatabdi", 1, "06:00"],
               ["Duronto", 3, "23:10"],
               ["Garib Rath", 1, "17:40"],
               ["Mail", 2, "09:15"]])
# ["Garib Rath", "Shatabdi", "Mail",
#  "Duronto", "Rajdhani"]

You may use sorted() here. The point is to use its stability and its key= well. Do not change trains.

Limits

  • Up to 100,000 trains.

Builds on SORT-7 Stability and sorted().

Continue on a laptop

Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.

Need a hint?0 of 3 opened

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

6 tests, not run yet
Test results
#TestResultReads · time
1Five trainsNot run
2Equal times keep their orderNot run
3Times as textNot run
4Empty boardNot run
5Input not changedNot run
6100,000 trainsNot run