Network disconnected
Description
Suppose that you want to check if an array of length n
contains numbers 1 through n
only once, without duplicates.
Write a function solution
to return true when the numbers 1 through n
only appears once, without duplicates, and false otherwise.
Constraints
- Length of array is less than or equal to 100,000.
- Each element of array is an integer between 0 and 100,000.
Examples
arr | result |
---|---|
[4, 1, 3, 2] | true |
[4, 1, 3] | false |
Example #1
When [4, 1, 3, 2] is given as input, an array should contain all numbers 1 through 4 because the length of the array is 4. Since [4, 1, 3, 2] contains all numbers 1 through 4, true should be returned.
Example #2
When [4, 1, 3] is given as input, an array should contain all numbers 1 through 3 because the length of the array is 3. However, [4, 1, 3] contains 4 instead of 2, therefore false should be returned.
Result
Stop
Result of [Run Test] or [Submit] will be displayed here