Problem · Array
Maximum Score with Prime Jumps
Learn this problemProblem statement
You are given an integer array cell representing a row of cells numbered from 0 to cell.length - 1. The value of cell[0] is always 0.
A player starts at cell 0 with a score of 0. On each move, the player may:
- Move one cell to the right.
- Move
pcells to the right, wherepis a prime number whose decimal representation ends in3.
The player may not move beyond the final cell. Whenever the player lands on a cell, that cell's value is added to the score. The game ends when the player reaches cell cell.length - 1.
Return the maximum possible score.
Function
maximumScore(cell: int[]) → longExamples
Example 1
cell = [0,-10,-20,-30,50]return = 40There are three ways to reach cell 4:
- Jump
3cells and then move1cell, scoring-30 + 50 = 20. - Move
1cell and then jump3cells, scoring-10 + 50 = 40. - Move
1cell four times, scoring-10 - 20 - 30 + 50 = -10.
The maximum possible score is 40.