This is a algorithm question.
You have an array of intergers, and a window of size k, you want to find the maximum number within the window starting from each index. Then return an array.
Example:
input: [1,3,2,4,3,5,6,3,8]
window size = 3;
output:[3,4,4,5,6,6,6,8,8]
The naive method takes O(nk) runtime, where n is the size of array.
Can anyone think of some algorithms that has a better run time?