Movie Ratings
Learn this problemProblem 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[]) → intComplete 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 = 4The 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
- Binary CircuitSeen Jul 2026
- Minimize Malware Spread by Removing a NodeOA · Seen Jul 2026
- Sort Array by FrequencyOA · Seen Jul 2026
- Array Challenge (QR Intern)OA · Seen Jul 2026
- Communications HandlerOA · Seen Jul 2026
- K Smallest SubstringOA · Seen Jul 2026
- Maximum K-Star SumOA · Seen Jul 2026
- Delivery Management SystemOA · Seen Jul 2026