A regional foundry issues permit numbers to its licensed workshops starting at 1 and always counting upward. Over the years some permits have been revoked and struck from the active ledger, while newly issued permits keep raising the highest number ever granted. You are given the complete list of permit numbers that are currently active, each appearing at most once. Find every permit number from 1 up to the highest currently active number that does NOT appear on the active list — these gaps mark revoked or never-reissued permits — and report them in ascending order.
Line 1: a single integer n, the number of active permit numbers. Line 2: n distinct integers, the active permit numbers, separated by spaces.
The gap numbers, in ascending order, separated by single spaces on one line. If there are no gaps, print an empty line.
Example 1
Input
3 2 5 6
Expected
1 3 4
Explanation
The active numbers are 2, 5, 6; the highest is 6, so numbers 1 through 6 are checked. Numbers 1, 3, and 4 are absent, so they are reported in ascending order: 1 3 4.
Example 2
Input
1 4
Expected
1 2 3
Explanation
Only permit 4 is active, so the highest active number is 4 and numbers 1 through 4 are checked. Numbers 1, 2, and 3 are absent, giving the gaps 1 2 3.
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 →