Skip to main content
deleted 2636 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4

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 , 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 , which tags should I use?

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 , 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

Meta

  • Any suggestion of any kind?
  • Apart from , which tags should I use?
added 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4

Standard rules apply for your answer, with default I/O rules.
Default Loopholes are forbidden.

This is , the shortest wins.

This is , the shortest wins.

This is , the shortest wins.

Standard rules apply for your answer, with default I/O rules.
Default Loopholes are forbidden.

This is , the shortest wins.

added 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4

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.

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.

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.

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.

added 18 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
edited body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 2 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 42 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 42 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 169 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 436 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 1 character in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 426 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 9 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 2 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 520 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 2 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
deleted 2 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
added 2 characters in body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
edited body
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading
Source Link
anotherOne
  • 1.1k
  • 3
  • 4
Loading