I will use two pointers, and both of them will start moving from the beginning of an array, but in different cases. The faster pointer will always move one step forward, but the slow pointer will only move when their distance is greater than K. Once the distance of two pointers is K, I will record the max number between them.
I will use the Sliding Window algorithm for this question, where I will maintain a window size of K, and keep track of maximum number in the window.
算法课
算法课
算法课