Answer the question
In order to leave comments, you need to log in
How to determine the continuity of array values and find breaks?
There is a pre-sorted array A of N integer values.
It is required to determine whether it is continuous, i.e. A[n+1] = A[n]+1 and split this array into subarrays, wherever this condition is met.
So far, nothing has come to mind, except for a stupid search to check the condition A[n+1] = A[n]+1, I wanted to ask if there are faster ways?
Answer the question
In order to leave comments, you need to log in
value step fixed?
is it "1" ?
binary search is at your fingertips. you can predict the value of any
A[n]both the original array and the fragment. based on the deviation, we can conclude that there is a gap (or several)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question