Given an array of integers, find "the next to the middle".
The next to the middle is the smallest integer greater than the smallest among mean, median and mode of the given numbers, that is neither the mean, median or mode and is also contained in the array.
For example, in the following array
[ 7, 5, 2, 8, 0, 2, 9, 3, 5, 1, 2 ]
Mean: 4
Median: 3
Mode: 2
The next to the middle is 5
, because:
- It's greater than 2 (the smallest of the three)
- It is not any of the mean, median, mode
- It's present in the input array
- It's the smallest number matching the above requirements
Another example, given this array
[ 2, 5, 1, 11, -1, 2, 13, 5, 1, 0, 5 ]
Mean: 4
Median: 2
Mode: 5
The next to the middle is 11
.
Input
An array containing a sequence of integers.
You don't need to handle integers larger than those that your language's data type can handle
The mean could be a floating point number and that's just fine.
If the number of elements in the input array is even, you need to handle 2 medians.
If more than one integer occurs with the highest frequency, you need to handle multiple values for the mode.
Output
The next to the middle.
If such number doesn't exist you can output either 3.14
, an empty string or any other value that cannot be mistaken for an element of the array (be consistent with that value throughout your program).
Standard rules apply for your answer, with default I/O rules.
Default Loopholes are forbidden.
This is code-golf, the shortest wins.
Test cases
[ 7, 5, 2, 8, 0, 2, 9, 3, 5, 1, 2 ]
5
[ 2, 5, 1, 11, -1, 2, 13, 5, 1, 0, 5 ]
11
[ ] // empty array
NaN
[ 528, -314, 2, 999, -666, 0, 0, 78 ]
78
[ 528, -314, 2, 999, -666, 0, 0, 79 ]
79
[ 528, -314, 2, 999, -666, 5, -5, 42 ]
NaN
[ -845, 2021, 269, 5, -1707, 269, 22 ]
5
[ -843, 2021, 269, 5, -1707, 269, 22 ]
2021
[-54,-22,-933,544,813,4135,54,-194,544,-554,333,566,566,-0522,-45,-45,]
-333
[95444,-22668,834967,51713,321564,-8365542,-962485,-253387,-761794,-3141592,-788112,533214,51713,885244,522814,-41158,-88659176,654211,74155,-8552445,-22222]
-3141592
[ 1, 2, 3, 9, 8, 7, 9, 8, 5, 4, 6, 0, 6, 7 ]
NaN
MetaPosted
- Any suggestion of any kind?
- Apart from code-golf, which tags should I use?