Q:
I do not know how to write an algorithm that outputs the maximal value of
the difference (s[k] - s[k-2]) for arbitrary sequence of integers
s[1],¡K., s[n], where 2<n, 2<k<=n.
thanks your help!
A:
Just go through all the elements of the array and calculate the
differences. When you start s[3]-s[1] is the start value and this is the
biggest so far. Store it in a variable. Then go on and if you find a
bigger store than one in the max variable.
Regards,
Peter
[ back to toc ]