#C3055. Permutation Verification
Permutation Verification
Permutation Verification
Given an integer N and an array of N integers, determine whether the array is a permutation of the first N natural numbers (i.e., contains every number from 1 to N exactly once). If the array is a permutation, output True
; otherwise, output False
.
For example, if N = 4 and the array is [4, 3, 1, 2], then the answer is True
because it contains all integers from 1 to 4 exactly once. Conversely, if the array has duplicate values or missing elements, the answer is False
.
Note: The input will be provided via standard input and the output should be sent to standard output.
inputFormat
The first line contains an integer N which denotes the expected size of the permutation.
The second line contains N space-separated integers representing the elements of the array. If N is 0, the second line may be empty.
outputFormat
Output a single line: True
if the array is a permutation of the first N natural numbers, otherwise False
.
4
4 3 1 2
True
</p>