There are pre-sorted array a of N integer values.

You want to determine whether it is continuous, i.e. A[n+1] = A[n+1] and break this array into subarrays wherever this condition was respected.

There is nothing in your head except for stupid overkill to check the condition A[n+1] = A[n+1] does not come, I wanted to ask is there any faster ways?

You want to determine whether it is continuous, i.e. A[n+1] = A[n+1] and break this array into subarrays wherever this condition was respected.

There is nothing in your head except for stupid overkill to check the condition A[n+1] = A[n+1] does not come, I wanted to ask is there any faster ways?

asked June 5th 19 at 21:00

2 answers

answered on

Solution

the step values fixed?

this "1" ?

binary search in your hands. you can predict the value of any

we must remember that Dvina the sample will be effective in determination of continuous fragments, further breaks may require a modification of the heuristic algorithm

ps for sure!.. in General, all the arguments about arithmetic progressions and binary search is true for any step of the progression (not just 1)

this "1" ?

binary search in your hands. you can predict the value of any

A[n]as the original array, and fragment. the deviation is possible to conclude that there is a gap (or several)

we must remember that Dvina the sample will be effective in determination of continuous fragments, further breaks may require a modification of the heuristic algorithm

ps for sure!.. in General, all the arguments about arithmetic progressions and binary search is true for any step of the progression (not just 1)

answered on

Solution

this is an arithmetic progression. The sum of the elements of the array compare it with the amount of progression, if not equal to run binary search how to write inside, you can also cecati amount

Find more questions by tags AlgorithmsProgramming