Jump Game with Prime-Step Rule
Updated
Problem statement
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.
Function
canReachWithPrimeSteps(nums: int[]) → int 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
Example 1
nums = [2, 3, 1, 1, 0]return = 0From 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.
Example 2
nums = [1, 1, 1, 1]return = 0Every 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 Online Assessment questions
- Count Palindromic Ancestor PathsOA · Seen Aug 2026
- Jump Game with Prime-3 StepsOA · Seen Aug 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Pipeline Throughput Maximization Under BudgetOA · Seen May 2026
- Balanced Prefix Sets in a PermutationOA · Seen Apr 2026
- Minimum Edge Reversals to Root a TreeOA · Seen Apr 2026
- Maximum Riders in CarOA · Seen Apr 2026
- Graph Palindrome QueriesOA · Seen Apr 2026
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions
- Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Find Encrypted NumberAmazon · OA
- Prime StringSnowflake · OASnowflake interview questions
- Valid PasswordsMathWorks · OAMathWorks interview questions