Minimum Jumps with Parity-Restricted Jump Lengths
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Coin ChangeKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Coin ChangePinterest · ONSITE INTERVIEWPinterest interview questions
- Coin ChangeBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
- Fewest Jumps to the End or StuckAdobe · PHONE SCREENAdobe interview questions
- Coin ChangeGrubhub · PHONE SCREENGrubhub interview questions
- Largest Diamond of Ones in a GridRippling · PHONE SCREENRippling interview questions
- Global Charger AssignmentSpotify · ONSITE INTERVIEW
- Minimum Taps to Water a GardenThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions