O(n) algorithm for sliding window maximum