You are given an integer array nums. You start at index 0 and want to reach index n - 1.
From index i, you may jump to any later index j if the step length j - i is prime and j - i <= nums[i].
Return 1 if the last index is reachable, otherwise return 0.
Complete the function canReachWithPrimeSteps in the editor below.
canReachWithPrimeSteps has the following parameter:
int[] nums: the maximum jump lengths
Returns
int: 1 if the end is reachable, otherwise 0.
Examples
01 · Example 1
nums = [2, 3, 1, 1, 0] return = 0
From index 0 (nums[0]=2), the only valid prime step is 2, reaching index 2. From index 2 (nums[2]=1), no prime step is possible because the minimum prime is 2 but nums[2]=1 < 2. No path reaches the last index, so the answer is 0.
02 · Example 2
nums = [1, 1, 1, 1] return = 0
Every allowed jump length is at most 1, and 1 is not prime.
Constraints
1 <= nums.length <= 2 * 10^50 <= nums[i] <= 10^9
More Uber problems
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
public int canReachWithPrimeSteps(int[] nums) {
// write your code here
}
nums[2, 3, 1, 1, 0]
expected0
sign in to submit