Solution to 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

Migration Notice

The current hosting service will be closed on September 30th. I am finding another free hosting service and migrating my blog. There might be some interruptions. Please be patient 🙂

Update on 2017/09/26: the service has been migrated to another hosting server. Please leave me a message if you met any error. Thanks!

Update on 2017/11/12: the previous service is quite unstable. I am migrating to another server. Thanks!

Admin 2017/09/20

Guideline for Comments

tl;dr: Please put your code into a <pre>YOUR CODE</pre> section.

Hello everyone!

If you want to ask a question about the solution. DO READ the post and comments firstly.

If you had some troubles in debugging your solution, please try to ask for help on StackOverflow, instead of here.

If you want to post some comments with code or symbol, here is the guidline.

1. To post your code, please add the code inside a <pre> </pre> section (preferred), or <code> </code>. And inside the pre or code section, you do not need to escape < > and &, e.g. no need to use &lt; instead of <.

2. To use special symbols < and > outside the pre block, please use "&lt;" and "&gt;" instead.

3. If you have a comment with lots of < and >, you could add the major part of your comment into a <pre class="decode:true crayon-inline "> YOUR COMMENTS </pre> section.

Finally, if you are posting the first comment here, it usually needs moderation. Please be patient and stay tuned. Thanks!

CodeSays.com Admin

Recent Comments

Sheng May 21, 2018 at 9:00 am on Solution to Passing-Cars by codilityNo. The if-closure ends with a "return" statement. No matter it's included within the loop or after, it will be executed at most once. In...

Sheng April 26, 2018 at 11:43 pm on Solution to Genomic-Range-Query by codilityThe "detected time complexity" is not always accurate. Because ""'A' in sub_S" is an O(N) operation, I would take your solution as O(N*M).