return the maximum values of subarray

This Question Was Asked By Google

An array of integers and a number k are given, where 1 <= k <= length of the array. You have to return the maximum values of each subarray of length k.

Write a function solve that have the following parameter(s):
1.) arr= an array
2.) k= an integer

Example
Input:
array = [10, 5, 2, 7, 8, 7] k = 3
Output:
[10, 7, 8, 8]

Explanation
For 10 = max(10, 5, 2)
For 7 = max(5, 2, 7)
For 8 = max(2, 7, 8)
For 8 = max(7, 8, 7)

Constraints
• The size of an array should be greater than 0 or less than 10000.
• The elements of an array should be greater than 0 and less than 1000.
• The value of k should be greater than 0 and less than 10000.