Answer the question
In order to leave comments, you need to log in
Difference of array elements
Good afternoon!
I have a question that I can't find an answer to.
So, there is a list of numbers, their number is not predetermined.
It is necessary to find out if there are at least three numbers in this list, the difference between which does not exceed a predetermined value.
So the question is how can this be done.
Thank you for your attention!
Answer the question
In order to leave comments, you need to log in
Sort, then sequentially look at the array for a match to the condition. If it is necessary that the total difference between the numbers does not exceed the specified value, then do a cycle from 0 to n-2, in which to compare a[i] ca[i+2]. With a[i-2]-a[i] <= m, return True, after the loop — False. (n is the number of the last array element (array size), m is a given number that must not be exceeded, i is a counter).
Implement, I hope, will not be difficult?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question