Created
January 24, 2015 13:44
-
-
Save rtcoms/3d35f6bb6cd84fd5a42a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
arr = [2, 4, 67, 0, 12, 7] | |
def reach_end arr | |
current_max_index = arr[0] | |
hop_count = 0 | |
last_index_of_array = arr.size - 1 | |
puts "=-"*5 | |
puts "CURRENT_MAX_INDEX : #{current_max_index}" | |
puts "=-"*5 | |
while(current_max_index < last_index_of_array) | |
hop_count += 1 | |
if last_index_of_array <= current_max_index | |
break | |
else | |
puts current_max_index = arr[1..current_max_index].max | |
end | |
end | |
puts hop_count + 1 | |
end | |
reach_end(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment