Consider an array x
such as [1 5 3 4]
and a number n
, for example 2
. Write all length-n
sliding subarrays: [1 5]
, [5 3]
, [3 4]
. Let the minimax of the array be defined as the minimum of the maxima of the sliding blocks. So in this case it would be the minimum of 5, 5, 4
, which is 4
.
Challenge
Given an array x
and a positive integer n
, output the minimax as defined above.
The array x
will only contain positive integers. n
will always be at least 1
and at most the length of x
.
Computation may be done by any procedure, not necessarily as defined above.
Code golf, fewest bytes wins.
Test cases
x
, n
, result
[1 5 3 4], 2 4
[1 2 3 4 5], 3 3
[1 1 1 1 5], 4 1
[5 42 3 23], 3 42