Trains the technique from
LeetCode 1696Jump Game VIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A row of pads holds the scores scores. You begin on the first pad and must finish on the last one. From a pad you may hop forward to any pad at most k places ahead, so long as it is still on the row.
Your total is the sum of the scores of every pad you stand on, counting the first and the last.
Return the largest total possible.
Example 1
A hop of two places clears the heavy loss in the middle, so only the two ends are stood on.
Example 2
A hop of one place forces every pad to be stood on, the loss included.
Example 3
Every pad scores something, so standing on all of them is best, and hops of one place manage exactly that.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_result(scores: list[int], k: int) -> int:public int maxResult(int[] scores, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.