8 kyu

Find the first non-consecutive number

27,623 of 69,629thecodeite

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 null2.

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 null2 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
Arrays
Fundamentals

More By Author:

Check out these other kata created by thecodeite

Stats:

CreatedApr 20, 2017
PublishedApr 20, 2017
Warriors Trained116830
Total Skips11382
Total Code Submissions295110
Total Times Completed69629
JavaScript Completions27623
Python Completions23215
Ruby Completions1502
Crystal Completions38
Java Completions8113
C# Completions3662
Haskell Completions480
Swift Completions1624
Julia Completions83
C Completions1682
Dart Completions920
Nim Completions62
Rust Completions1203
Scala Completions225
TypeScript Completions934
COBOL Completions21
C++ Completions90
λ Calculus Completions4
Total Stars1123
% of votes with a positive feedback rating91% of 5958
Total "Very Satisfied" Votes5002
Total "Somewhat Satisfied" Votes817
Total "Not Satisfied" Votes139
Total Rank Assessments15
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • thecodeite Avatar
  • GiacomoSorbi Avatar
  • natan Avatar
  • shadowmanos Avatar
  • donaldsebleung Avatar
  • imjasonmiller Avatar
  • JohanWiltink Avatar
  • Souzooka Avatar
  • metagn Avatar
  • monadius Avatar
  • hobovsky Avatar
  • stellartux Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Knaque Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • o2001 Avatar
  • KayleighWasTaken Avatar
  • SummerTheCoder Avatar
Ad