A O(N) Dynamic Programming way :
Divide array by N/L blocks, last one maybe less than L.
For example, X=[2,1,3,4,6,3,8,9,10,12,56] ,L= 4
Then after divide, X= 2,1,3,4 | 6,3,8,9 | 10,12,56
notation:
Right_peak(i): peak value of all the elements on the right hand of X[i] (include X[i]) in the same block.
Left_peak(i): peak value of all the elements on the left hand of X[i] (include X[i]) in the same block.
Then, the peak(i), value of subarray X[i : i+L-1] should be max{ Right_peak(i), Left_peak(i+L-1) }
Proof:
if i is the first position of a block, then the Right_peak(i) equal to Left_peak(i+L-1) is the peak value of this block, Also the subarray X[i : i+L-1].
If i is not the first position of a block, then the Right_peak(i) is the peak value of the rest of the block. The Left_peak(i+L-1) is the peak value of the beginning elements of the next block. Combined together they are the subarray X[i: i+L-1]. So the maximum of the two parts is the peak value of the subarray.
Using the above example:
X= 2,1,3,4 | 6,3,8,9 | 10,12,56
We can find the Left_Peak value while traversing from left to right of the current block. ( At each end of the block the Left_peak value should reset to 0.) O(N)
Left_peak[]= 2,2,3,4| 6,6,8,9 | 10,12,56
We can find the Right_peak value while traversing from right to left of the current block. ( At each end of the block the Left_peak value should reset to 0.). O(N)
Right_peak[]= 4,4,4,4 | 9,9,9,9 | 56,56,56
Then peak(i)=max{ Right_peak(i), Left_peak(i+L-1) }
peak[]=[4,6,6,8,9,10,12,56]
Simply find the minimux of peak[] and output the index of it. O(N)
The subarray is X[ index: index+L-1]
which is X[1: 4]