Untitled

 avatar
Darin
plain_text
a year ago
576 B
3
Indexable
Never
int announce(int mDuration, int M) {
    Queue<Employee> queue = new PriorityQueue<>((a, b) -> a.end - b.end);
    int maxAnnounceEnd = 0;
    for (Employee e : set) {
        if (e.start < maxAnnounceEnd) {
            continue;
        }
        queue.add(e);
        int announceEnd = e.start + mDuration - 1;
        maxAnnounceEnd = Math.max(maxAnnounceEnd, announceEnd);
        while (!queue.isEmpty() && queue.peek().end < announceEnd) {
            queue.poll();
        }
        if (queue.size() == M) {
            return e.start;
        }
    }
    return -1;
}