Jump Game with Prime-3 Steps
Updated
Problem statement
You are given an integer array cities. A positive value is money you gain in that city. A negative value is money you spend there.
You start in the first city, and its value counts toward your total. You can only move to the right. From city index i, one move can take you to:
- the next city, at index
i + 1, or - city
i + p, wherepis a prime number whose last digit is3.
Every move must stay inside the array, and you must end in the final city. Add up the values of every city you visit, including the first and final cities. Return the largest total you can get.
Function
maxJumpScore(cities: int[]) → intExamples
Example 1
cities = [5,-100,4,10]return = 15Jump directly from index 0 to index 3. The jump length 3 is prime and ends in 3, so the total is 5 + 10 = 15.
Example 2
cities = [4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,20]return = 24Jump directly from index 0 to index 13. The jump length 13 is prime and ends in 3, so the total is 4 + 20 = 24.
Example 3
cities = [7]return = 7The first city is already the final city, so the answer is its value.
Constraints
1 <= cities.length <= 5000-10000 <= cities[i] <= 10000- The first and final cities always count toward the total.
- A move that skips cities must cover a prime distance whose last digit is
3.
More Agoda Online Assessment questions
- Special Diameter EndpointsOA · Seen Nov 2025
- TV Series in a Production WindowOA · Seen Nov 2025
- Count One Groups by SizeOA · Seen Jul 2025
- Minimum Price With Discount CouponsOA · Seen Jul 2025
- Lexicographically Smallest Task QueueOA · Seen Jul 2025
- Highest-Ranked University by CountryOA · Seen Jun 2025
- Team FormationOA · Seen Apr 2025
- Two-Core Process AssignmentOA · Seen Apr 2025
- Unique Digits in RangeOA · Seen Apr 2025
- Maximize Sum of Processed TimesOA · Seen Sep 2024
Similar questions at other companies
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Pascal's TriangleJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA