Create Maximum of all subarrays of size k.java

The efficient algorithm that runs at O(n) time here is to us a data structure dequeue, which only stores those element that could be the max value in the future (basically the dequeue only stores the value in descending order). Why? for example if you have element [10, 5, 3] and the new 11 comes in, then 10 5, 3 will not be the maximum number for any of the continuous subarray anymore. But if you have 2 comming in, then 5, and 3 could be the maximum number in the future subarray. so keep them in the dequeue.