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
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
6 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Five trains | Not run | |
| 2 | Equal times keep their order | Not run | |
| 3 | Times as text | Not run | |
| 4 | Empty board | Not run | |
| 5 | Input not changed | Not run | |
| 6 | 100,000 trains | Not run |