A team of financial analysts at Amazon closely monitors revenue generated by a newly launched product. They classify a period of one or more consecutive days as a stable-growth period if the revenue generated by the product takes no more than k distinct values over that period.
Given an array revenues of size n, that represents the revenues generated by the new product on n consecutive days, and an integer k, determine the total number of stable growth periods over the n days. Since the answer can be large, return it modulo (10^9 + 7).
Complete the function getStablePeriodsCount in the editor.
getStablePeriodsCount has the following parameters:
int revenues[n]: the revenues generated by the new product overndaysint k: the maximum number of distinct values in a stable growth period
Returns
int: the number of stable growth periods of the product over n days, modulo (10^9 + 7)
revenues = [1, 2, 1] k = 1 return = 3

k=1 or fewer distinct values. The number of stable growth periods is 3.revenues = [2, -3, 2, -3] k = 2 return = 10
n ≤ 10^5k ≤ nrevenues[i] ≤ 10^9- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
public int getStablePeriodsCount(int[] revenues, int k) {
// write your code here
}