Maximize Movie Ratings Without Consecutive Skips
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Oracle reported this one in July 2026, and the title sounds like a sliding window problem. It isn't. Strip the movie theme and it's a one-pass DP over two states: did you take the last movie or skip it. The rule that you can't skip two in a row is the whole twist, and negative ratings make greedy fall apart. If you have this OA in the next day or two, learn the recurrence below. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic here is short enough to hold in your head.
The problem
You are given an integer array ratings, where ratings[i] is the rating of the movie at position i. You may select or skip each movie. Maximize the sum of the selected ratings subject to this rule: you may not skip two consecutive movies. For an array containing one movie, you may skip that movie and return 0. For every longer array, your choices must still satisfy the no-two-consecutive-skips rule. Return the maximum total as a signed 64-bit integer. Function maxMovieRatings(ratings: int[]) → long Examples Example 1 ratings = [5,-1,4] return = 9 Select ratings 5 and 4 and skip -1. The selected total is 9, and only one movie is skipped. Example 2 ratings = [-5,-2,-3] return = -2 Skip the first and third movies and select the middle rating -2. The two skipped positions are not adjacent. Example 3 ratings = [-7] return = 0 A single movie may be skipped, so the best total is 0. Example 4 ratings = [6,-4,-5,7] return = 9 The ratings -4 and -5 cannot both be skipped. Select 6, -4, and 7 for a maximum total of 9. Constraints 1 <= ratings.length <= 200000. -2^31 <= ratings[i] <= 2^31 - 1. The returned value fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Track two values per index: take[i], the best total if you select movie i, and skip[i], the best total if you skip movie i. Then take[i] = ratings[i] + max(take[i-1], skip[i-1]), and skip[i] = take[i-1], because skipping i forces i-1 to be selected. Start with take[0] = ratings[0] and skip[0] = 0. The answer is max(take[n-1], skip[n-1]). Example 4 shows why it works: [6,-4,-5,7] forces you to pay for one negative. The pitfalls are using 32-bit ints, since sums can reach about 200000 times 2^31, and ignoring the single-element case, which returns max(ratings[0], 0). Only two rolling variables are needed, so space is O(1) and time is O(n). If you blank during the live OA, StealthCoder can hand you this recurrence, but you should still be able to explain it.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Maximize Movie Ratings Without Consecutive Skips 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximize Movie Ratings Without Consecutive Skips FAQ
What's the real trick in Maximize Movie Ratings Without Consecutive Skips?+
It's a two-state DP, not a sliding window. Keep the best total ending with a taken movie and the best ending with a skipped movie. A skip can only follow a take, which encodes the no-two-consecutive-skips rule cleanly in a few lines.
Why doesn't a greedy approach work here?+
Negative ratings break it. You'd like to skip every negative, but two negatives in a row force you to take one. Example 4 shows this: you must take either -4 or -5. Greedy can't choose which one without looking ahead, and DP handles that.
Do I need 64-bit integers?+
Yes. With up to 200000 elements and values near 2^31, the sum overflows a 32-bit int easily. Use long in Java or C++, and be careful with the initial values and any negative sentinels you pick.
What edge cases should I test before submitting?+
Test a single element, like [-7] returning 0 and a positive single element returning itself. Test all negatives, like Example 2, and an all-positive array where you take everything. Also try two elements, since one must be taken.
How do I prepare for this in 48 hours?+
Practice the House Robber style DP until you can write the two-state recurrence without looking. Then adapt it to this inverted rule, where skips are limited instead of takes. Run the four examples by hand, and do one pass on overflow.