Loading...
You are given an integer array nums of length n. A token starts on index 0 and must reach index n - 1.
From an index i, the token may move in one of two ways:
i + 1.i + p, where p is a prime number whose last digit is 3 (that is, p is one of 3, 13, 23, 43, 53, 73, ...) and i + p < n.Each time the token lands on an index, including the starting index 0 and the final index n - 1, it collects the value stored there. Return the maximum total value the token can collect over all valid paths from index 0 to index n - 1.
Because a unit step is always available, index n - 1 is always reachable.
Input: nums = [10,-5,-10,20,10]
Output: 40
Explanation: The only usable prime ending in 3 that is at most 4 is 3.
Prime-jump from index 0 to index 3 (collecting 10, then 20), then a unit step
from index 3 to index 4 (collecting 10). Total = 10 + 20 + 10 = 40.
Input: nums = [10,-100,-100,10,-100,-100,10]
Output: 30
Explanation: Two prime jumps of length 3 give the path 0 -> 3 -> 6, collecting
10 + 10 + 10 = 30. Every unit-step path is forced through the -100 values, so
jumping is strictly better.
nums.length ≤104nums[i] ≤104Click "Run" to test with sample cases or "Submit" to run all tests.