Jump Game Variant
Examples
Example 1:
Input: nums = [5,-100,4,10]
Output: 15
Explanation:
Example 2:
Input: nums = [4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,20]
Output: 24
Explanation:
Example 3:
Input: nums = [7]
Output: 7
Explanation:
Example 1:
Input: nums = [5,-100,4,10]
Output: 15
Explanation:
Example 2:
Input: nums = [4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,20]
Output: 24
Explanation:
Example 3:
Input: nums = [7]
Output: 7
Explanation:
You are given an integer array nums where nums[i] is the score at index i.
You start at index 0 and want to reach index n - 1. Every time you land on an index, you add that index's value to your total score. The starting index 0 counts as already landed on, so nums[0] is included in the total.
From index i, you may jump only to the right by:
1 step, orp steps where p is a prime number whose last digit is 3Examples of allowed prime jumps include 3, 13, 23, and so on.
Return the maximum total score you can collect when you land on index n - 1.
Jump directly from index 0 to index 3 using a 3-step jump. The score is nums[0] + nums[3] = 5 + 10 = 15.
A 13-step jump is allowed because 13 is prime and ends in 3. Jumping directly from 0 to 13 gives 4 + 20 = 24.
You start on the last index, so the answer is just nums[0].
1 <= nums.length <= 10^5-10^4 <= nums[i] <= 10^41 or by any prime number whose last digit is 3.