10958: Codility - PermCheck
[Creator : ]
Description
A non-empty array $A$ consisting of $N$ integers is given.
A permutation is a sequence containing each element from $1$ to $N$ once, and only once.
For example, array $A$ such that:
A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2
is a permutation, but array $A$ such that:
A[0] = 4 A[1] = 1 A[2] = 3
is not a permutation, because value $2$ is missing.
The goal is to check whether array $A$ is a permutation.
Input
The first line is $N\ (1 \leq N \leq 100,000)$.
The second line consist of n numbers $A_i\ 1 \leq A_i \leq 10^9)$.
Output
returns
Yes
if array $A$ is a permutation.
If it is not, return which number is missing. Sample 1 Input
4
4 1 3 2
Sample 1 Output
Yes
Sample 2 Input
3
4 1 3
Sample 2 Output
2
Sample 3 Input
4
1 2 3 4
Sample 3 Output
Yes