#K89442. Mex After Removal
Mex After Removal
Mex After Removal
You are given a permutation of the integers from 1 to (n). Since the permutation contains all integers from 1 to (n), it does not include 0. For each position in the permutation, remove that element and determine the smallest non-negative integer (the mex) that is not present in the remaining set. Note that because 0 is not in the original permutation, the answer will always be 0. Your task is to compute and output a list of (n) integers where the (i)th integer is the mex of the permutation after removing the (i)th element.
inputFormat
The first line contains an integer (n) ((1 \le n \le 10^5)), the length of the permutation. The second line contains (n) space-separated integers representing a permutation of the numbers from 1 to (n).
outputFormat
Output a single line containing (n) space-separated integers. The (i)th integer should be the mex (minimum excluded non-negative integer) of the permutation after removing the (i)th element.## sample
5
4 3 1 2 5
0 0 0 0 0