Maximum Game Score with Fixed Forward Jumps
Updated
Problem statement
You are given an integer array gameVal of length n and an integer k.
A player picks any index as the starting position. From index i, the player jumps forward exactly k positions to index i + k, and keeps jumping this way while the new index is inside the array. The walk ends only when the next jump would leave the array, so the player cannot stop early.
The player's score is the sum of the values at every visited index, including the starting index.
Return the maximum score the player can get by choosing the best starting position.
Function
maxGameScore(gameVal: int[], k: int) → intExamples
Example 1
gameVal = [2,-3,4,6,1]k = 2return = 7- Start at index
0: visit0 -> 2 -> 4for2 + 4 + 1 = 7. - Start at index
1: visit1 -> 3for-3 + 6 = 3. - Start at index
2: visit2 -> 4for4 + 1 = 5. - Start at index
3or4: the next jump leaves the array, so the scores are6and1. - The best score is
7.
Example 2
gameVal = [-2,5,-6,3,-1]k = 1return = 2- With
k = 1, each start walks to the end of the array. - The scores for starts
0to4are-1,1,-4,2and-1. - Starting at index
1collects5first, but the walk must go on through-6,3and-1, which leaves1. - The best score is
2, from index3:3 + (-1) = 2.
Example 3
gameVal = [-5,-1,-3,-2]k = 2return = -2- Start at index
0:-5 + (-3) = -8. Start at index1:-1 + (-2) = -3. - Start at index
2:-3. Start at index3:-2. - Every score is negative, and the best one is
-2.
Constraints
n == gameVal.length2 <= n <= 10^5-1000 <= gameVal[i] <= 10001 <= k <= n - 1
More Stripe Online Assessment questions
- Asynchronous Event ProcessingOA · Seen Nov 2026
- Reliable LLM Call with Independent Retry BudgetsOA · Seen Nov 2026
- Request Routing SystemOA · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Chat Billing CalculationOA · Seen Nov 2026
- Deployment Window SchedulerOA · Seen Nov 2026
- Subscription and Usage-Based Billing CalculatorOA · Seen Nov 2026
- Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
- Incident MonitorOA · Seen Nov 2026
- Split Tender Part 3 - SurchargesOA · Seen Nov 2026
Similar questions at other companies
- Minimize Sum of Distances to WarehousesAmazon · OA
- Maximum Apples from Two Disjoint Fixed-Length SegmentsMarshall Wace · OAMarshall Wace interview questions
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
- Maximize CollaborationTikTok · OATikTok interview questions
- Maximum Sum RectangleDeloitte · OADeloitte interview questions
- Maximum Subarray Sum with Equal EndpointsGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximum Subarray SumCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Minimum Variance Sum SplitAirbnb · PHONE SCREENAirbnb interview questions
- Largest All-One Square Area and CountNVIDIA · PHONE SCREENNVIDIA interview questions
- Most Visited Sprint MarkerMicrosoft · OAMicrosoft interview questions