FastPrepMaximize Movie Ratings Without Consecutive Skips
Problems/Maximize Movie Ratings Without Consecutive Skips

Maximize Movie Ratings Without Consecutive Skips

Oracle logoOracle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source does not define boundary behavior, numeric limits, or return width. The judged core task matches the visible source at about 94%.

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.

More Oracle problems

  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public long maxMovieRatings(int[] ratings) {
      // write your code here
    }
}
Checking account…