Sliding Window Maximum

Problem Id: 239 Difficulty: Hard


Intuition

Solution


class Solution:
    # O(k*n) Solution
    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
        if not nums:
            return []

        result = []
        for i in range(len(nums)-k+1):
            result.append(max(nums[i:i+k]))
        return result