Sliding Window Maximum

Xem dạng PDF

Gửi bài giải

Điểm: 100,00
Giới hạn thời gian: 2.0s
Giới hạn bộ nhớ: 256M

Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python

Task

Given a sequence of integers and a window size k, compute the maximum value in each sliding window of size k.

For a sequence of length n, there are n - k + 1 windows:

  • Window 0: elements 0..k-1
  • Window 1: elements 1..k
  • ...
  • Window n-k: elements n-k..n-1

Input

  • Line 1: two integers n k
  • Line 2: n space-separated integers

Output

Print n - k + 1 integers, one per line — the maximum of each window.

Example

Input

8 3
1 3 -1 -3 5 3 6 7

Output

3
3
5
5
6
7

Notes

  • Track E: Python stdlib only — no numpy, no scipy.

Scaffolding

def sliding_window_max(nums: list[int], k: int) -> list[int]:
    ...

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.