Problem · Dynamic Programming

Movie Ratings

Learn this problem
MediumAkuna CapitalFULLTIMEOA

Problem statement

Alex loves movies and maintains a list of negative and/or positive integer ratings for the movies in a collection. Alex is getting ready for a film festival and wants to choose some subsequence of movies from the collection to bring such that the following conditions are satisfied:

  • The collective sum of their ratings is maximal.
  • Alex must go through the list in order and cannot skip more than one movie in a row. In other words, Alex cannot skip over two or more consecutive movies. For example, if ratings = [-1, -3, -2], Alex must include either the second number or the first and third numbers to get a maximal rating sum of -3.

Function

maximizeRatings(ratings: int[]) → int

Complete the function maximizeRatings in the editor below.

maximizeRatings has the following parameter(s):

int ratings[n]: movie ratings

Returns

int: the maximum possible rating sum for a subsequence of movies

Input Format for Custom Testing

The first line contains an integer n, the size of the array ratings.

Each of the next n lines contains an integer ratings[i].

Examples

Example 1

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

The maximal choices are [2, 4, -2] for a sum of 4.

Example 2

ratings = [9, -1, -3, 4, 5]return = 17

🦢 Source note: I added this example on July 15, 2026 based on a new source found today.

One optimal choice is [9, -1, 4, 5]. It skips only -3 and has a total rating of 17.

Constraints

  • 1 ≤ n ≤ 10^5
  • -1000 ≤ ratings[i] ≤ 1000, where 0 ≤ i < n

More Akuna Capital problems

drafts saved locally
public int maximizeRatings(int[] ratings) {
  // write your code here
}
ratings[-3, 2, 4, -1, -2, -5]
expected4
checking account