/**
 * Given an array of non-negative integers, you are initially positioned at the first index of the array. 
 * Each element in the array represents your maximum jump length at that position.
 * Determine if you are able to reach the last index.
 */

 /**
  * time: O(n)
  * space: O(1)
  * score:86.99(7ms)
  */
class Solution {
    public boolean canJump(int[] nums) {
        int n = nums.length;
        int lastPos = n - 1;
        //Break down to the subquestion: Can I reach the goal at point i with jump distance of nums[i]
        for (int i = n - 1; i >= 0; i--) {
            if (i + nums[i] >= lastPos) {
                lastPos = i;
            }
        }
        return lastPos == 0;
    }
}