I have the next problem, and I was wondering whether it exists a way to solve it without having to iterate around all the array in the worst case.
I have a sorted array of pairwise distinct integers, say $[1,2,4,5,7,8]$ I need to know if there is a gap of at least two between two consecutive integers, i.e., if there are successive integers $a$ and $b$ in the list with $b>a+2$.
For example in the array given, the algorithm should return false, but for $[2,3,6,7]$, it should return true. Is it possible to solve it by mathematics instead of iterate and compare the integers one by one?
I will add some inputs and the desired output:
- [1,2,4] -> false
- [1,2,5] -> true
- [1,2,4,6,8] -> false
- [1,3,4,6,8] -> false
- [1,4,6,8] -> true
- [1,3,5] -> false