Maximize Ratings
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], and must include either the second number or the first and third numbers to get a maximal rating sum of -3.
Complete the function maximizeRatings in the editor below.
maximizeRatings has the following parameter(s):
int ratings[n]: movie ratings
Returns
int: the maximum sum of the ratings of the chosen subsequence of movies
1Example 1
The maximal choices are [2, 4, -2] for a sum of 4.
2Example 2
Alex picks the bolded items in ratings = [9, -1, -3, 4, 5] to get maximum rating = 9 + 4 + 5 = 17.
Constraints
Limits and guarantees your solution can rely on.