Given an integer list where each number represents the number of hops, you can make, determine whether you can reach to the last index starting at index 0.

For example, `[2, 0, 1, 0]`

returns `true`

while `[1, 1, 0, 1]`

returns `false`

.

**Problem Explanation:** In the above list [2, 0, 1, 0], **2** is the first element so we can make **two** jump to and our current element will be **1** and we can make **one** jump and can reach the last element and so returns **true**.

#### Ruby Solution:

def reaches_last(arr, current_index, target) return true if current_index == target jump = arr[current_index] if (current_index + jump > target) or jump == 0 return false end return reaches_last(arr, current_index+jump, target) end arr = [2, 0, 1, 1] reaches_last(arr, 0, arr.length-1) # Returns true

#### Explanation:

reaches_last function accepts array, current_index, and last element. The problem condition will be satisfied if we reach the last_element ie., (target). So, return true if current_index==target. I used recursion here to check the current index with the next hop. The hop value is jump = arr[current_index]. We should return false if our current_index is greater than target and also if jump == 0, because we can’t jump more if jump=0.

*Also, see: PYTHON TUTORIAL FOR BEGINNERS*

*Share and Support! ❤️*