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 an array of integers and a window size w, return the maximum value in each contiguous subarray of length w. The output has length n - w + 1.

Input

  • Line 1: two ints n w
  • Line 2: n space-separated ints

Output

n - w + 1 space-separated integers on one line.

Example

Input:

6 3
1 3 2 5 4 6

Output:

3 5 5 6

Scaffolding

def window_max(arr: list[int], w: 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.