As reported: Salesforce SMTS onsite (India, July 2025), round 1 (DSA); a brute-force solution that did not pass all tests was not enough.
Movies are shown in order; ratings[i] is the rating of movie i (it can be negative). You choose which movies to watch, but you may not skip two or more consecutive movies. Return the maximum possible sum of the ratings of the movies you watch.
Example 1
ratings = [-3,2,4,-1,-2,-5]
Output: 4
Skip -3, watch 2 and 4, skip -1, watch -2, skip -5: 2 + 4 − 2 = 4.
Example 2
ratings = [9,-1,-3,4,5]
Output: 17
Skip -1, watch -3: 9 − 3 + 4 + 5 = 15 is worse than skipping -3 and watching -1: 9 − 1 + 4 + 5 = 17.
Constraints: 1 ≤ ratings.length ≤ 10^5; -1000 ≤ ratings[i] ≤ 1000.
Clarifications
- Skipping the first or the last movie is allowed, as long as no two skipped movies are adjacent.
Code runner format: one line: ratings as a JSON array. Implement maxRating(ratings); the harness prints the total.