Last active
March 29, 2021 09:17
-
-
Save thephw/c48d9b1714f2f3a5bb9c to your computer and use it in GitHub Desktop.
Find the index of the max ascending slice in an array
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 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