Maximum Subarray Minimum

Company: ibm_7nov

Difficulty: medium

Problem Statement

Maximum Subarray Minimum Problem Description You are given an array arr of n integers and a subarray length k . Consider every contiguous subarray of arr of size exactly k , and take the minimum value inside each one. Return the largest of those minimums. A subarray is obtained by deleting several (possibly zero) elements from the beginning and from the end of the original array, so the elements of a subarray are contiguous in arr . Input Format The first line contains the integer n , the length of the array. The next n values are the elements of arr (they may be spread over one or more lines). The last value is the integer k , the subarray length. Output Format Print a single integer: the maximum among the minimums of all contiguous subarrays of size k . Examples Example 1 5 1 2 3 4 5 2 Output: 4 For k = 2 the subarrays are [1,2] , [2,3] , [3,4] and [4,5] . Their minimums are 1 , 2 , 3 and 4 , and the largest of those is 4 . Example 2 5 1 2 3 1 2 1 Output: 3 For k = 1 every element is