educative.io

Educative

Can we do this with simple recursion?

Can’t we just use a simple recursive solution like this?

def find_max_sliding_window (arr, window_size)
  helper(arr, window_size)
end 

def helper(a, w, acc = [])
  return acc if a.empty?
  return acc if a.size < w
  acc << a.slice(0, w).max
  helper(a.slice(1, a.length), w, acc)
end

Hi Dan! Yes, we can use recursion to solve this problem as well. Your implementation is also correct!