Minimum Jumps with Parity-Restricted Jump Lengths
Problem statement
You are given a non-negative array nums. From index i, you may jump forward by any length from 1 through nums[i].
Jump numbers are one-based: the first jump must have odd length, the second jump even length, the third odd, and so on. Return the minimum jumps needed to reach the last index, or -1 if impossible.
An array of length one requires zero jumps.
Function
minimumParityJumps(nums: int[]) → intExamples
Example 1
nums = [2,3,1,1,4]return = 3Use jump lengths 1, 2, and 1 to reach indices 1, 3, and 4.
Example 2
nums = [3,2,1,0,4]return = -1No parity-respecting sequence reaches the final index.
Example 3
nums = [0]return = 0The start is already the destination.
Constraints
1 <= nums.length <= 5000.0 <= nums[i] <= nums.length.