Maximize a Fixed-Step Game Score by Choosing the Start
Company: Stripe
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Online Assessment
Overview: Maximize fixed-step game scores with backward dynamic programming, preserving mandatory jumps, negative totals, and the distinction from optional early stopping.
Read the full Stripe Software Engineer interview experience this question came from
Constraints
- The array contains 1 through 2^31 − 1 entries.
- Every value lies between −(2^53 − 1) and 2^53 − 1 inclusive. The step k lies between 1 and 2^53 − 1 inclusive.
- The maximum score fits in the same signed range as the input values. Other path sums may fall outside that range.
Examples
Input: ([2, -3, 4, 6, 1], 2)
Expected Output: 7
Explanation: Starting at index 0 gives 2 + 4 + 1, the best score.
Input: ([9, -20, 5], 1)
Expected Output: 5
Explanation: Starting at 0 requires taking the negative suffix. Starting at 2 alone scores 5.
Hints
- A starting position determines the entire path because every in-bounds jump is required.