Amazon Shopping recently launched a new item whose daily customer ratings for n days is represented by the array ratings. They monitor these ratings to identify
products that are not performing well. Find the number of groups that can be formed consisting of 1 or more consecutive days such that the rating continuously decreases over the days.
The rating is consecutively decreasing if it has the form: r, r – 1, r-2… and so on, where r is the rating on the first day of the group being considered. Two groups are considered different if they contain the ratings of different consecutive days.
Example
ratings = [4, 3, 5, 4, 3]
There are 9 periods in which the rating consecutively decreases.
5 one day periods: [4], [3], [5], [4], [3]
3 two day periods: [4, 3], [5, 4], [4, 3]
Function Description
Complete the function countDecreasing Ratings in the editor.
countDecreasingRatings contains one parameter:
int ratings[n]. customer ratings for n days
Returns
long. the number of valid groups of ratings
Constraints
• 1 <= n <= 10^5
• O <= ratings[i] <= 10^9
Input Format For Custom Testing
The first line contains an integer, n, the number of elements in ratings.
Each line i of the n subsequent lines (where 0 <= i < n) contains an integer that describes ratings[i].
Sample Case 0
Sample Input For Custom Testing
| STDIN | FUNCTION |
| —– | ——– |
| 3 | ratings[] size n = 3 |
| 2 | ratings [2, 1, 3] |
| 1 | |
| 3 | |
Sample Output
4
Explanation
There are 4 groups of continuously decreasing ratings: [2], [1], [3], [2, 1].
How would you go for a question like this?