Find the first non-consecutive number
Description:
Your task is to find the first element of an array that is not consecutive.
By not consecutive we mean not exactly 1 larger than the previous element of the array.
E.g. If we have an array [1,2,3,4,6,7,8]
then 1
then 2
then 3
then 4
are all consecutive but 6
is not, so that's the first non-consecutive number.
If the whole array is consecutive then return null
2.
The array will always have at least 2
elements1 and all elements will be numbers. The numbers will also all be unique and in ascending order. The numbers could be positive or negative and the first non-consecutive could be either too!
1 Can you write a solution that will return null
2 for both []
and [ x ]
though? (This is an empty array and one with a single number and is not tested for, but you can write your own example test. )
2
- Swift, Ruby and Crystal:
nil
- Haskell:
Nothing
- Python, Rust, Scala, Lambda Calculus:
None
- Julia:
nothing
- Nim:
none(int)
(See options) - C++:
std::nullopt
Similar Kata:
Stats:
Created | Apr 20, 2017 |
Published | Apr 20, 2017 |
Warriors Trained | 116830 |
Total Skips | 11382 |
Total Code Submissions | 295110 |
Total Times Completed | 69629 |
JavaScript Completions | 27623 |
Python Completions | 23215 |
Ruby Completions | 1502 |
Crystal Completions | 38 |
Java Completions | 8113 |
C# Completions | 3662 |
Haskell Completions | 480 |
Swift Completions | 1624 |
Julia Completions | 83 |
C Completions | 1682 |
Dart Completions | 920 |
Nim Completions | 62 |
Rust Completions | 1203 |
Scala Completions | 225 |
TypeScript Completions | 934 |
COBOL Completions | 21 |
C++ Completions | 90 |
λ Calculus Completions | 4 |
Total Stars | 1123 |
% of votes with a positive feedback rating | 91% of 5958 |
Total "Very Satisfied" Votes | 5002 |
Total "Somewhat Satisfied" Votes | 817 |
Total "Not Satisfied" Votes | 139 |
Total Rank Assessments | 15 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |