← Back to challenges

Consecutive Numbers

PythonHardarraysloopssortingvalidation

Instructions

Create a function that determines whether elements in an array can be re-arranged to form a consecutive list of numbers where each number appears exactly once.

Examples

cons([5, 1, 4, 3, 2]) ➞ True
// Can be re-arranged to form [1, 2, 3, 4, 5]

cons([5, 1, 4, 3, 2, 8]) ➞ False

cons([5, 6, 7, 8, 9, 9]) ➞ False
// 9 appears twice

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Crowded Carriage Capacity