A community nursery packs seedlings into numbered seed packets before shipping them out each morning. The packing station's labeler is configured to stamp every packet with an integer code between 0 and n-3, inclusive, and under normal operation each of these n-2 possible codes is stamped onto exactly one packet, for a total of n packets. This morning the labeler jammed twice, so two of the codes each ended up stamped onto two separate packets instead of one, while every other code still appears on exactly one packet. You are given the codes read off all n packets, in the order they came off the belt. Identify the two codes that were stamped twice.
n, the number of packets.n space-separated integers, the codes read off the packets in belt order.Print the two duplicated codes, in increasing order, separated by a single space.
4 <= n <= 2000000 and n-3, inclusive.0 to n-3 appears at least once among the n codes, exactly two distinct codes appear exactly twice, and every other code appears exactly once.Example 1
Input
4 0 1 0 1
Expected
0 1
Explanation
There are n=4 packets and codes should range over 0..n-3 = 0..1. Counting occurrences: code 0 appears twice and code 1 appears twice. The two duplicated codes, in increasing order, are 0 and 1.
Example 2
Input
6 1 3 0 2 1 3
Expected
1 3
Explanation
There are n=6 packets and codes range over 0..3. Counting occurrences: 0 appears once, 1 appears twice, 2 appears once, 3 appears twice. The two codes stamped twice are 1 and 3, printed in increasing order.
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 →