Implement the minimumJumpsToReachEnd method that finds the minimum jumps required to reach the last index.

The input contains an integer array nums and its length size. Each value tells the maximum number of positions you can jump forward from that index.

Your task is to return the minimum number of jumps needed to reach the last index. If the last index cannot be reached, return -1. For example, in [2,3,1,1,4], you can jump from index 0 to index 1, then to the last index, so the answer is 2.

Example 1
Input:
nums (int[]) = [2,3,1,1,4]
size (int) = 5
Return:
(int) 2
Example 2
Input:
nums (int[]) = [3,2,1,0,4]
size (int) = 5
Return:
(int) -1
Example 3
Input:
nums (int[]) = [0]
size (int) = 1
Return:
(int) 0

Use a greedy range-based approach.

Think of each jump as covering a range of indexes. While scanning the current range, keep track of the farthest index that can be reached by the next jump.

When the scan reaches the end of the current range, one jump is completed and the next range begins. If the current range cannot move forward, the last index is unreachable.

Pseudocode:

function minimumJumpsToReachEnd(nums, size):
    if size <= 1:
        return 0
    if nums[0] == 0:
        return -1
    jumps = 0
    currentEnd = 0
    farthest = 0
    for i from 0 to size - 2:
        farthest = max(farthest, i + nums[i])
        if i == currentEnd:
            jumps++
            currentEnd = farthest
            if currentEnd >= size - 1:
                return jumps
            if currentEnd == i:
                return -1
    return -1
Run your code to see the result.