2023 Huawei OD machine test real question Python implementation [maximum sliding window]

Table of contents

topic

Ideas

Test points

Code


topic

Title description:
There is an array of N integers and a window of length M. The window starts sliding from the first number in the array until the window cannot slide. Each time the window slides, a window sum (all numbers in the window) is generated. and), find the maximum value of all window sums generated by window sliding.

Input description:
Enter a positive integer N in the first line, representing the number of integers. (0<N<100000)
Enter N integers in the second line. The value range of the integers is [-100,100].
The third line inputs a positive integer M, M represents the size of the window, M<=100000, and M<=N.
Output description:
Window sliding produces the maximum value of all window sums.
Example 1 input and output examples are for debugging only, and the background judgment data generally does not contain examples.

Input
6
12 10 20 30 15 23
3
Output
68

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/132775969