A city relay race hands out bib numbers 1 through n to its n registered runners, one number per runner, with no gaps and no repeats when everything goes right. This year the bib-printing machine jammed partway through: it printed one bib number twice (so two different runners ended up wearing the same number) and, because the machine only prints n stubs total, one bib number from 1 to n was never printed at all.
You are given the ledger of n bib numbers exactly as recorded from the printed stubs, in no particular order. Exactly one value in the ledger appears twice, and exactly one value from 1 to n is absent from the ledger. Report which bib number was duplicated and which bib number is missing.
Line 1: an integer n. Line 2: n space-separated integers, the recorded bib numbers.
Print two space-separated integers: the duplicated bib number, then the missing bib number.
Example 1
Input
4 1 2 2 4
Expected
2 3
Explanation
The ledger has runners wearing 1, 2, 2, 4. Bib 2 was printed for two runners (duplicate), and bib 3 never got printed (missing), so the answer is "2 3".
Example 2
Input
2 1 1
Expected
1 2
Explanation
With n=2 both stubs read 1, so bib 1 is the duplicate. Bib 2, the only other valid number, was never printed, so the answer is "1 2".
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 →