Maximize Movie Ratings With Skip Limit

Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Salesforce OA. Under 2s to a working solution.
Founder's read

The mistake that sinks most first attempts at this Salesforce OA, reported in July 2025, is grabbing every positive rating and calling it done. The catch is the rule: you can't skip two movies in a row. So a negative movie sometimes has to be watched to bridge a gap. It's a small dynamic programming problem dressed up as a movie list. If the state doesn't click in the first few minutes, StealthCoder runs invisibly during the live OA and hands you the solution as a safety net. Know the recurrence and you won't need it.

The problem

You are given an integer array ratings, where ratings[i] is the rating of the i-th movie.
You may choose to watch or skip each movie, but you cannot skip two or more movies consecutively.
Return the maximum possible sum of watched movie ratings while respecting the skip constraint.

Function
maximizeMovieRatings(ratings: int[]) → int

Examples
Example 1
ratings = [-3,2,4,-1,-2,-5]
return = 4

Constraints
1 <= ratings.length
-1000 <= ratings[i] <= 1000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a two-state DP over the array. Let watch[i] be the best sum ending with movie i watched, and skip[i] the best sum with movie i skipped. Watching can follow either state: watch[i] = ratings[i] + max(watch[i-1], skip[i-1]). Skipping is only allowed if the previous movie was watched: skip[i] = watch[i-1]. Answer is max(watch[n-1], skip[n-1]). Roll it into two variables for O(1) space. The common pitfall is the greedy take-all-positives approach, which breaks when two negatives sit side by side, since you must watch one. Another trap is the start: the first movie can be skipped freely, so skip[0] = 0 and not negative infinity. Check Example 1: [-3,2,4,-1,-2,-5] gives 4. If you blank on the base case mid-assessment, StealthCoder is the hedge that gets you unstuck without leaving the screen.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Maximize Movie Ratings With Skip Limit cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

Salesforce reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Movie Ratings With Skip Limit FAQ

What's the trick to the Salesforce Maximize Movie Ratings problem?+

Track two states per index: last movie watched or last movie skipped. Watching can follow either state. Skipping only follows a watched movie. That enforces the no-two-skips rule. The answer is the max of both states at the end. It's linear time and constant space.

Why doesn't greedy work here?+

Greedy takes every positive and skips every negative. That fails when two negatives are adjacent, because skipping both breaks the rule. You'd have to watch one, and which one matters. DP handles that choice by comparing both options at each step.

How should I handle the first movie?+

Treat skipping the first movie as allowed, with a skipped sum of 0. There's no previous skip before it. Set watch to ratings[0] and skip to 0. Getting this wrong is the most common off-by-one bug, and it'll shift your answer on the sample.

How hard is this really?+

It's easy to medium. It's the same family as house robber style DP, with the constraint flipped to limit skips instead of picks. If you've seen that pattern, you can write this in about ten minutes. The edge cases are all negative ratings and a length of one.

How do I prepare in 48 hours?+

Write the two-variable DP from scratch twice. Test all-negative arrays, a single element, and the sample [-3,2,4,-1,-2,-5] returning 4. Then do one or two similar adjacent-constraint DP problems. That's enough. Don't spend the time on unrelated topics.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Salesforce.

OA at Salesforce?
Invisible during screen share
Get it