AmazonOA #87
Get Stale Skill Count
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersHashing
Each log entry is a skillId and a timestamp. For each query q, count the skills that have no request in the closed interval [q−timeWindow,q]; output the answers in the input order of the queries.
Input
The first line contains numSkills m q timeWindow, all four in 1..100000; then m lines of skill timestamp, then one line of q queryTime values. skill is in 1..numSkills, and all times are in 1..100000.
Output
One line of q inactive counts, separated by spaces.
Example 1
Input:
3 2 2 2
1 1
2 3
3 4
Output:
1 2
Example 2
Input:
2 1 2 1
1 5
5 1
Output:
1 2
Example 3
Input:
1 2 1 1
1 1
1 2
2
Output:
0
Example notes
Example 1: for q=3 the window [1,3] contains skills 1 and 2, so 1 skill is inactive; for q=4 the window [2,4] contains only skill 2, so 2 are inactive. Example 2: query 5 has skill 1, so 1 is inactive; query 1 has no logs, so 2 are inactive, and the original order is kept. Example 3: both log entries belong to skill 1, which counts as only one active skill, so 0 are inactive.
Editorial
Loading solution…