The first question was a House Robber variation with extra logic involving prime numbers, as follows.
Problem description
A traveler moves through cities represented by an integer array. Each integer gives the amount of money spent, if negative, or earned, if positive, in that city per day. The journey starts at city 0 and ends at city n-1. The traveler can move to the adjacent city or to a city p steps away, where p is a prime number ending in 3.
Determine the maximum money the traveler can have at the end.
Example
cities = [0, 100, 200, -500, -100, -150, -50].
The optimal journey ends with 100.
The traveler starts at city 0, moves to city 1 and earns 100, then to city 2 for 100 + 200 = 300, then to city 2 + 3 = 5 for 300 + (-150) = 150, and finally to city 6 for 150 + (-50) = 100.
The traveler only moves to city i+1 or i+3 here, since 3 is the only prime ending in 3 within this array's range.
Function description
Complete optimalJourneyTotal with the parameter int cities[n], where cities[i] is the money earned or spent in city i. Return an integer representing the maximum money at the end.
Constraints
1 <= n <= 10^4.
-10^4 <= cities[i] <= 10^4.
cities[0] = 0.
The second question was just LeetCode 2560 with a different story.
Discussion
Loading comments…