Computer Science, asked by tavisha5946, 11 months ago

Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k. For example, given array = [10, 5, 2, 7, 8, 7] and k = 3, we should get: [10, 7, 8, 8], since:

Answers

Answered by Coding
0

Answer:

def max_in_subarray(array, k):

   max_values = []

   for i in range(len(array) - k + 1):

       max_values.append(max(array[i:i+k]))

   return max_values

Explanation:

Python solution. The runtime is O(n).

Similar questions