AmazonOA #152
Find Kth Minimum Vulnerability
Estimated HardJudge-ready
Topics (AI-labelled)Two PointersStacks & HeapsBinary Search
For each contiguous window of length m in the array, sort it in ascending order and take the k-th value. Repeated values each take their own position, and the answers are output in ascending order of window start.
Input
The first line contains n m k (1≤k≤m≤n≤300000), and the second line contains n vulnerability values (1..10^9).
Output
Output the k-th smallest values of the n−m+1 windows.
Example 1
Input:
4 3 2
1 3 2 1
Output:
2 2
Example 2
Input:
5 4 3
4 2 3 1 1
Output:
3 2
Example 3
Input:
3 2 2
5 5 1
Output:
5 5
Example notes
Example 1: both windows sort to 1, 2, 3, and the 2nd item is 2 in both. Example 2: the windows sort to 1, 2, 3, 4 and 1, 1, 2, 3, so the 3rd items are 3 and 2 respectively. Example 3: the repeated 5s each take a position, so the 2nd smallest of both windows is 5.
Editorial
Loading solution…