Skip to content

Instantly share code, notes, and snippets.

@rtcoms
Created January 24, 2015 13:44
Show Gist options
  • Save rtcoms/3d35f6bb6cd84fd5a42a to your computer and use it in GitHub Desktop.
Save rtcoms/3d35f6bb6cd84fd5a42a to your computer and use it in GitHub Desktop.
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