Skip to content

Instantly share code, notes, and snippets.

@nikasulo
Created August 24, 2019 20:42
Show Gist options
  • Save nikasulo/88d814d8ec9eeef3ceca37ecc0a1a53f to your computer and use it in GitHub Desktop.
Save nikasulo/88d814d8ec9eeef3ceca37ecc0a1a53f to your computer and use it in GitHub Desktop.
A brute force solution to the sliding maximum problem
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
@nikasulo
Copy link
Author

nikasulo commented Aug 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment