A coastal authority operates a straight chain of n unmanned monitoring stations, numbered 0 through n - 1 from one end of the shoreline to the other. Every station continuously reports a numeric status code. Whenever a station's status code equals a specific alert code, that station is said to be broadcasting a beacon alert.
A station is considered inside a proximity zone if there is some station — possibly the station itself — whose distance along the chain from it is at most k, and which is currently broadcasting the beacon alert.
Given the alert code and the radius k, report every station index that lies inside a proximity zone.
The first line contains three integers n, alertCode, and k.
The second line contains n integers — the status codes of stations 0 through n - 1, separated by single spaces.
It is guaranteed that at least one station's status code equals alertCode.
Print the indices of every station inside a proximity zone, in strictly increasing order, separated by single spaces, on one line. At least one index is always printed.
alertCode.Example 1
Input
6 2 2 3 4 9 1 2 1
Expected
2 3 4 5
Explanation
Station 4 has status code 2, matching the alert code, so it is broadcasting a beacon alert. With k = 2, every station within distance 2 of station 4 is inside a proximity zone, i.e. the range [4-2, 4+2] = [2, 6], clipped to the valid range [2, 5] since the chain only has indices 0..5. Station 4 itself is included because its distance to itself is 0. Stations 0 and 1 are farther than 2 from the only alert station, so they are excluded. The result is 2 3 4 5.
Example 2
Input
5 2 2 2 2 2 2 2
Expected
0 1 2 3 4
Explanation
Every station's status code equals the alert code 2, so every station is itself broadcasting a beacon alert (distance 0 to itself is always at most k). Hence all five stations, indices 0 through 4, are inside a proximity zone.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →