This problem is "inspired" from a question that was originally asked on Quora (not for code golfing). I just want to make it a challenge for you guys (and my first problem submission here).
Given an array of integer elements
v and an integer
d (we assume that d is lower or equal to the array's length), consider all the sequences of
d consecutive elements in the array. For each sequence, compute the difference between the maximum and minimum value of the elements in that sequence and name it the deviation.
Your task is to write a program or function that computes the maximum value among all deviations of all the sequences considered above, and return or output that value.
v: (6,9,4,7,4,1) d: 3 The sequences of length 3 are: 6,9,4 with deviation 5 9,4,7 with deviation 5 4,7,4 with deviation 3 7,4,1 with deviation 6 Thus the maximal deviation is 6, so the output is 6.
This is code golf, so the shortest answer in bytes wins.