Skip to the code
+50 XP

#501 Hop Through Slides for Max Score

hard

A presenter clicks through a deck of slides, and scores[i] is how much the audience likes slide i (it can be negative). The talk starts on slide 0 and must end on the last slide. Each click jumps forward between 1 and reach slides.

Write maxSlideScore(scores, reach) that returns the largest total score of the slides shown, counting the first and the last slide.

Example 1

Input: scores = [2,-1,-3,5,-8,4], reach = 2
Output: 10

Show slides 0, 1, 3, 5: 2 - 1 + 5 + 4.

Example 2

Input: scores = [8,-4,-3,5,0,2], reach = 3
Output: 15

Show slides 0, 3, and 5: 8 + 5 + 2.

Constraints

  • 1 <= scores.length <= 100000
  • 1 <= reach <= 100000
  • -10000 <= scores[i] <= 10000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).