Maximize the Score of Bounded Forward Jumps

Quick Overview

Maximize the Score of Bounded Forward Jumps. Start at index 0 of nums and finish at its final index. Each jump advances between 1 and k positions without leaving the array. Your score includes the values at every visited index, including the start and finish.

Maximize the Score of Bounded Forward Jumps

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Start at index 0 of `nums` and finish at its final index. Each jump advances between 1 and `k` positions without leaving the array. Your score includes the values at every visited index, including the start and finish. Return the greatest possible score. ```cpp class Solution { public: int maxResult(vector<int>& nums, int k); }; ``` ### Examples **Example 1:** ```text nums = [2,-3,4,-2,5], k = 2 Output: 11 Explanation: Visit indices 0, 2, and 4. ``` **Example 2:** ```text nums = [-2,-5,-1], k = 1 Output: -8 Explanation: Every index must be visited when the maximum jump is one. ``` ### Constraints - Both `nums.length` and `k` lie in `[1,10^5]`. - `-10^4 <= nums[i] <= 10^4`. ### Clarifying Questions Forward steps cannot have length zero. Negative values are allowed and the route must still reach the last index. ```hint Inspect the structure What must a valid route include even when some visited values are negative? ``` ### Reasoning checkpoints - Include both endpoints and use only forward jumps of allowed length. - Prove the maximum score even when every available continuation has a negative contribution. ### Optional extensions How does a heap-based sliding maximum compare with a monotone deque here?

Overview: Maximize the Score of Bounded Forward Jumps. Start at index 0 of nums and finish at its final index. Each jump advances between 1 and k positions without leaving the array. Your score includes the values at every visited index, including the start and finish.

Microsoft logo
Microsoft
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start at index 0 of nums and finish at its final index. Each jump advances between 1 and k positions without leaving the array. Your score includes the values at every visited index, including the start and finish. Return the greatest possible score.

class Solution {
public:
    int maxResult(vector<int>& nums, int k);
};

Examples

Example 1:

nums = [2,-3,4,-2,5], k = 2
Output: 11
Explanation: Visit indices 0, 2, and 4.

Example 2:

nums = [-2,-5,-1], k = 1
Output: -8
Explanation: Every index must be visited when the maximum jump is one.

Constraints

  • Both nums.length and k lie in [1,10^5] .
  • -10^4 <= nums[i] <= 10^4 .

Clarifying Questions Guidance

Forward steps cannot have length zero. Negative values are allowed and the route must still reach the last index.

Reasoning checkpoints

  • Include both endpoints and use only forward jumps of allowed length.
  • Prove the maximum score even when every available continuation has a negative contribution.

Optional extensions

How does a heap-based sliding maximum compare with a monotone deque here?