Codility MinAvgTwoSlice Java solution

preview_player
Показать описание
Codility MinAvgTwoSlice is an exercise in the Prefix Sums lesson on Codility. The goal is to find the slice in a given array where the lowest average value is is contained. A slice is a part of the array between any two values from zero to the length of the array.

Here is my Java solution to MinAvgTwoSlice that scores 100%.
Рекомендации по теме
Комментарии
Автор

I read this MinAvgTwoSlice so many times to understand what was being asked..kkkk
Now I got it. Thanks for sharing

fabionozoy
Автор

Thank you for this video. I suggest you use the prefix sums technique to solve this as it is what any interviewer is going to be looking for. I made a new array with one more index then the input array. Set element[0] to 0. Loop over and create a new array of sums. Write a method to get the sum of any slice that takes in an array and 2 ints with this formula sumOfSlice = arrayOfSums[endingInt +1] - arrayOsums[startingInt]

Nyxbynite
Автор

Thanks for posting. My solution was not very efficient. This might be a silly question but would you mind explaining how you came to the conclusion that we only need to look at subarrays with a length of either 2 or 3?

kathrynperry
Автор

Thanks, I thing it would be nice if you submit your codes to Github or something; it is hard to read from the video.

mertyertugrul