# Problem 56175. Dartboard Average II

A dartboard arranges the numbers 1 to 20 such that each value is typically flanked by quite different values - for example, 20 is flanked by 1 and 5, 16 by 8 and 7, and so on.
Assuming a player of questionable skill aiming for a particular value will hit that value or the value on either side with equal probability, what is the best and worst value to aim at? That is, what value has the highest and lowest average with the two values on either side?
Given a vector v representing the arrangement of the values 1 to 20, return the values with the maximum and minimum average with the values on either side. Note that a dartboard is circular, so the values in v are assumed to wrap.
For example, a standard dartboard is represented by
v = [20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];
For this v, your function should return 7 and 17 (in that order). The target value 7 has the highest average (mean([19 7 16]) = 14). Similarly, 17 has the lowest average (mean([2 17 3]) = 7.3333).
If there are multiple values with the highest or lowest average, your function should return the first of them. (For example, if v = [12 10 20 8 14 1 7...], both 10 and 8 have an average of 14. Your function should return 10 in this case.)
The vector v will always be a permutation of the values 1:20.

### Solution Stats

46.74% Correct | 53.26% Incorrect
Last Solution submitted on Jun 10, 2024

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!