Solution to Deviation

4 Sep

Question Name: Deviation

Question Description: Given an array of integer elements and an integer d, please consider all the sequences of d consecutive elements in the array. For each sequence we compute the difference between the maximum and the minimum value of the elements in that sequence and name it the deviation. Your task is to write a function that computes the maximum value among the deviations of all the sequences considered above, and print the value on the standard output (stdout).
Note that your function will receive the following arguments:
        v: which is the array of integers
        d: which is an integer value giving the length of the sequences
Data constraints
        the array will contain up to 100,000 elements
        all the elements in the array are integer numbers in the following range: [1, 2^31 -1]
        the value of d will not exceed the length of the given array
Efficiency constraints
        your function is expected to print the result in less than 2 seconds

The solution is inspired by Codility’s Lesson 13: Caterpillar Method.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!