def windowed_max_range(array, window_size)
  current_max_range = nil

  (0..array.length-window_size).each do |idx|
    check_array = array[idx...idx+window_size]
    min_value = check_array.min
    max_value = check_array.max
    range = max_value - min_value

    current_max_range = range if !current_max_range || range > current_max_range
  end

  current_max_range
end

p windowed_max_range([1, 0, 2, 5, 4, 8], 2)
p windowed_max_range([1, 0, 2, 5, 4, 8], 3)
p windowed_max_range([1, 0, 2, 5, 4, 8], 4)
p windowed_max_range([1, 3, 2, 5, 4, 8], 5)