Skip to content

Instantly share code, notes, and snippets.

@thephw
Last active March 29, 2021 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thephw/c48d9b1714f2f3a5bb9c to your computer and use it in GitHub Desktop.
Save thephw/c48d9b1714f2f3a5bb9c to your computer and use it in GitHub Desktop.
Find the index of the max ascending slice in an array
def index_of_max_ascending_slice(a)
slices = a.slice_when{|i,j| i >= j}.to_a
max_size = slices.map(&:length).max
start_index = slices[0...slices.find_index{|v| v.length == max_size}].flatten.count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment