Sliding Window Maximum

Find the maximum value in each sliding window of size k as it moves across the array.

Code

Algorithms
arr.each_cons(k).map(&:max)

Parameters

Array of numbers

Window size

Server

More Ruby Snippets