Created
August 24, 2019 20:42
-
-
Save nikasulo/88d814d8ec9eeef3ceca37ecc0a1a53f to your computer and use it in GitHub Desktop.
A brute force solution to the sliding maximum problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sliding_maximum(k, array) | |
res = [] | |
for i in 0..array.length - k do | |
max = array[i] | |
for j in i...i+k do | |
max = array[j] > max ? array[j] : max | |
end | |
res << max | |
end | |
res | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a brute force version of the solution to the sliding maximum problem tutorial I am writing. For the more optimal solution, check out the tutorail or the code to the optimal solution