implemented max in sliding window algorithm