Slide Count
InterviewTime limit1sMemory limit1024 MB
Given an array and a constant C, count for each element how many distinct windows produced by a two-pointer scan contain it.
- Level
Medium5 of 10
- Topics
- Two pointers, Sliding window, Prefix sum
- Solved
- No attempts yet
Problem
In your programming class, you are given an assignment to analyze an integer array with a sliding window algorithm. Given integers and a constant , the algorithm maintains start and end indices and as follows.
- Initially .
- As long as :
- if , increment ;
- else if , increment ;
- else increment .
Each distinct pair of indices that appears during the execution defines a window. Element belongs to the window if . If , the window is empty.
For the first sample, the windows are , , , , , , , , , and . For each element , count how many different windows it belongs to during the execution.
Input
The first line contains two integers (), the number of elements, and (), the window constant.
The next line contains integers ().
Output
For each element, in input order, print the number of different windows it belongs to during the execution of the algorithm.