#K71007. Consecutive Task Arrangement
Consecutive Task Arrangement
Consecutive Task Arrangement
You are given a list of task IDs. Your task is to determine whether it is possible to arrange this list into a consecutive sequence of integers with no gaps and no duplicates. In other words, when sorted, the numbers should form an arithmetic sequence with a common difference of 1.
For example:
- The list
[3, 2, 1, 4, 5]
can be rearranged into[1, 2, 3, 4, 5]
, which is consecutive, so the answer isTrue
. - The list
[1, 3, 2, 5]
cannot be rearranged into a consecutive sequence because there is a gap (4 is missing), so the answer isFalse
.
Note: An empty list should return False
and a list with one element is always considered consecutive.
The solution should read input from stdin and output the result to stdout.
inputFormat
The input is given from standard input (stdin). The first line contains an integer n
representing the number of tasks. The second line contains n
space-separated integers representing the task IDs.
outputFormat
Print True
if the task IDs can be rearranged into a consecutive sequence with no gaps and no duplicates; otherwise, print False
. The output should be written to standard output (stdout).
5
3 2 1 4 5
True