Skip to the code
cf.
+10 XP

#494 Spotlight Posts Without Neighbors

easy

A social feed shows posts in a fixed order, and scores[i] is the expected engagement of post i if it gets a spotlight badge. Two spotlighted posts may never sit next to each other in the feed, because they would look like one big block.

Write spotlightPosts(scores) that returns the largest total engagement you can get by choosing which posts to spotlight. Choosing no posts is allowed.

Example 1

Input: scores = [3,8,10,2,4]
Output: 17

Spotlight posts 0, 2, and 4: 3 + 10 + 4.

Example 2

Input: scores = [6,2,1,6]
Output: 12

Posts 0 and 3 are not neighbors: 6 + 6.

Constraints

  • 0 <= scores.length <= 1000
  • 0 <= scores[i] <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

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