Input: arr[] = {1, 2, 3, 4, 5}, K = 4
Output: 2
Explanation:
The subarrays of size 4 are {1, 2, 3, 4} and {2, 3, 4, 5}. The common elements in the above subarrays are {2, 3, 4}.
The minimum of the above common element is 2.
Input: arr[] = {1, 2, 3, 4, 5}, K = 2
Output: -1
Explanation:
The subarrays of size 2 are {1, 2}, {2, 3}, {3, 4}, {4, 5}. Since there is no common element, print -1.
If the above conditions don't satisfy, then the minimum element lies in the range [N - K, K]. Therefore, iterate over the given array in this range and print the value of the minimum element in it.