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. If cell contains only cell 0, return 0.
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.
Example 2
cell = [0,-100,-100,8]return = 8Because 3 is prime and ends in 3, the player can jump directly from cell 0 to cell 3. Only cell[3] is added, so the score is 8.
Example 3
cell = [0,5,4,3,2,1]return = 15Moving one cell at a time visits every positive-valued cell and gives 5 + 4 + 3 + 2 + 1 = 15. Taking a prime jump would skip positive values, so it cannot improve this score.
Constraints
1 <= cell.length <= 10^4cell[0] == 0-10^9 <= cell[i] <= 10^9for every valid indexi.
More Microsoft problems
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026