import java.util.*; public class Solution{ public ArrayList maxInWindows(int[] num,int size){ ArrayList result = new ArrayList<>();

    if(num == null || size <= 0 || size > num.length){
        return result;
    }
    LinkedList<Integer> list = new LinkedList<>();
    for(int i = 0;i < num.length; i++){
        while(!list.isEmpty() && num[list.peekLast()] <= num[i]){
            list.pollLast();
        }
        list.addLast(i);
        if(list.peekFirst() == i - size){
            list.pollFirst();
        }
        if(i >= size - 1){
            result.add(num[list.peekFirst()]);
        }
    }
    return result;
}

}