A city marathon assigns every runner a unique bib number from 0 to n-1. At the finish line, a timing chip system recorded, for each bib number, the numeric place in which that runner crossed the line (1st, 2nd, and so on) — but a printer malfunction means only this bib-to-place lookup survived, not the ordered results sheet itself. Given the lookup, reconstruct the finishing order: the list of bib numbers from whoever finished 1st down to whoever finished last.
n — the number of runners.n space-separated integers place_0, place_1, ..., place_{n-1}, where place_i is the 1-indexed finishing place of the runner wearing bib i. These values form a permutation of 1..n.Print a single line with n space-separated bib numbers, ordered from the runner who finished 1st to the runner who finished last.
place is a permutation of the integers 1 to nExample 1
Input
5 3 1 4 2 5
Expected
1 3 0 2 4
Explanation
place = [3, 1, 4, 2, 5] means bib 0 finished 3rd, bib 1 finished 1st, bib 2 finished 4th, bib 3 finished 2nd, and bib 4 finished 5th. Reading off the finishers in order of place 1 through 5 gives bib 1 (1st), bib 3 (2nd), bib 0 (3rd), bib 2 (4th), and bib 4 (5th), so the output is 1 3 0 2 4.
Example 2
Input
1 1
Expected
0
Explanation
With only one runner, bib 0 necessarily finished 1st, so the finishing order is just 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →