Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

There is a new product launched and its customer ratings are being recorded in an array. the ratings are being monitored and analyzed if there is any decrease in the ratings. find the number of periods in which the rating is consecutively decreasing.

example - ratings = [4,3,5,4,3]
periods (in other words sub arrays in which ratings are decreasing):
one day periods = [4],[3],[5],[4],[3] (count of subarrays is 5)
two day periods = [4,3],[5,4],[4,3] (count of subarrays is 3)
3 day periods = [5,4,3] (count of subarrays is 1)
so, the output for this example will be 9 (5 + 3 + 1)


Sagot :

The program to find the number of periods in which the rating is consecutively decreasing is; As written in the attached file

What is the program array?

What we are required to do to find the number of elements in decreasing part. For example;

4,3 means One decreasing part and has 2 elements

5, 4, 3 means second decresing part and has 3 element.

Thereafter, we just add n*(n + 1)/2 to result.

where;

n = number of elements in any part

n*(n + 1) /2 is number of decreasing subarray that can be made

For the second decreasing part which is [5, 4, 3];

number of sub arrays you can make = 3 * 4/2 = 6

Thus, we have;

[5], [4,], [3], [5,4],[4,3],[5,4,3]

The program to find the number of periods in which the rating is consecutively decreasing is as follows in the attached file;

Read more about program array at; https://brainly.com/question/16266708

View image AFOKE88