Jump Game in Python

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        Function to determine if it's possible to reach the last index of the array.

        The function implements a greedy algorithm approach. The key idea is to iterate through the array
        and keep track of the farthest reachable index. If at any point, the farthest reachable index
        is less than the current index, it means we cannot proceed further, and hence we cannot reach
        the end of the array.

        nums (List[int]): List of non-negative integers representing the maximum jump length at each position.

        bool: True if the last index can be reached, False otherwise.

        # Initialize the farthest reachable index to be the first index
        max_reachable = 0

        # Iterate over the array
        for i, jump_length in enumerate(nums):
            # If the current index is greater than the maximum reachable index, we cannot reach this point
            if i > max_reachable:
                return False

            # Update the maximum reachable index
            max_reachable = max(max_reachable, i + jump_length)

            # If the maximum reachable index is at or beyond the last index, return True
            if max_reachable >= len(nums) - 1:
                return True

        # If we finish iterating through the array without returning True, it means we cannot reach the end
        return False