MEXchange
InterviewTime limit1sMemory limit1024 MB
Given the prefix MEX sequence B, construct a permutation A that produces B, or report that no such permutation exists.
- Level
Medium5 of 10
- Topics
- Greedy, Implementation
- Solved
- No attempts yet
Problem
A permutation of length is a sequence in which each integer from to appears exactly once. For example, is a permutation, but is not, because appears twice. Also, has length but is not a permutation, because it contains .
Given a permutation of length , define the sequence as follows.
Given a sequence of length , find the permutation .
is the smallest positive integer not contained in the set . For example, and . Note that the defined in this problem can never be .
Input
The first line contains the length of the permutation .
The second line contains integers , separated by spaces, which are the elements of the sequence .
Output
On the first line, print Yes if a permutation that produces exists, and No otherwise.
If it exists, print the elements of the permutation on the second line, separated by spaces. If there are multiple answers, print any of them.