Given array A, length n and a natural number k such that 1 <= k <= n
.
Construct an array B size n-k+1
that suffices the following -
every B[j]
is the max between A[j],A[j+1],...A[j+k-1]
suppose to solve in linear time. for example:
A = {3,1,5,12,13,4,2} size 7 and k = 3. desired answer would be -
B = {5,12,13,13,13}
Note; this is not a homework question, but post exam question that I'm having trouble to solve.
Tried using Double-Ended Queue that will contain at the max k elements, but I'm having a problem tracking the kth maximum.