Given an array path and an integer maxStep, a cursor starts at index 0 with an initial sum equal to path[0]. From its current position, the cursor may move right by any number of positions from 1 to maxStep (inclusive) in a single move.
Whenever the cursor lands on a new position, the value at that position is added to the running sum. The cursor must eventually reach the last element of the array.
Determine the maximum possible sum that can be obtained upon reaching the final position.
path = [10, 2, -10, 5, 20]
maxStep = 2
One optimal journey is:
Therefore, the maximum possible sum is 37.