Uber OA-11 2023
Problem Description
In the thrilling world of "Jump Master," you embark on a daring journey through a magical land with mystical teleporting stones. You are gifted with the power to make forward jumps based on the range indicated by each stone. The challenge lies in reaching the final destination, marked by a glowing portal. Your goal is to find the shortest path using the stones wisely. Can you calculate the minimum number of jumps required to reach the coveted portal and unlock the secrets of the enchanted realm?
Input Format:
- An array of integers
nums
where each element represents the maximum number of steps that can be jumped forward from that index.
Output Format:
- An integer representing the minimum number of jumps required to reach the last index.
Constraints:
- 1 <=nums.length<=10^4
- 0<=nums[i]<= 1000
- It's guaranteed that you can reach the last index.
Sample Testcase 1:
Input:
nums = [2, 3, 1, 1, 4]
Output:
2
Explanation:
The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
Sample Testcase 2:
Input:
nums = [2, 3, 0, 1, 4]
Output:
2