AmazonOA #240
Get Stable Periods Count (Fungible :)
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersHashing
A non-empty contiguous period of the income array is stable if it contains at most k distinct income values. Count all stable periods modulo 1000000007; periods with different start or end positions are counted separately.
Input
The first line contains n k; the second line contains the incomes. 1≤n≤100000, 1≤k≤n, −10^9≤income≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
3 1
1 2 1
Output:
3
Example 2
Input:
4 2
2 -3 2 -3
Output:
10
Example 3
Input:
3 1
5 5 5
Output:
6
Example notes
The answers are 3, 10 and 6. A contiguous range of equal incomes may also span multiple dates.
Editorial
Loading solution…