← 返回 twosigma 的题目列表Jump Game Series
类型:online_judge
Given an array nums, you start at index 0. Each element represents the maximum jump length from that position.
Depending on the exact variant specified by the interviewer, solve one of the following:
Reachability (Jump Game I): determine if you can reach the last index.
Minimum jumps (Jump Game II): return the minimum number of jumps needed to reach the last index.
Reach a zero (Jump Game III): given start, from index i you can jump to i + arr[i] or i - arr[i]; determine if you can reach any index with value 0.
Minimum steps (Jump Game IV): from index 0, in one step you can move to i±1 or any index j with arr[j] == arr[i]; return the minimum steps to reach n-1.
Input format (example)
One line array, e.g. 2 3 1 1 4
(If applicable) an extra line start
Output format
Reachability: print true/false
Min jumps/steps: print an integer
Constraints (typical interview scale)
1 <= n <= 2*10^5 (depending on the variant)
Non-negative integers
Note: The interviewer usually specifies which variant; if unclear, clarify the exact requirements first.
Example
Input
2 3 1 1 4
Output
true