Problem 2349. Elements with highest local average

Input v is a row vector such that length(v)>3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.


Input: v=[1 2 3 4 5 6 7 8 9 -3 0 1];

Output: vOut=[7 8 9];

The consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.

Solution Stats

49.04% Correct | 50.96% Incorrect
Last Solution submitted on Jun 26, 2020

Solution Comments