import java.util.*;
public class Solution {
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        ArrayList<Integer> res = new ArrayList<>();
        if(size == 0) return res;
        int hh = 0,tt = -1;
        int[] arr = new int[num.length];
        for(int i = 0;i < num.length;i++){
            if(hh <= tt && i - arr[hh] >= size) hh++;
            while(hh <= tt && num[i] > num[arr[tt]]) tt--;
            arr[++tt] = i;
            if(i >= size - 1 && hh <= tt) res.add(num[arr[hh]]);
        }
        return res;
    }
}