Untitled
Darin
plain_text
2 years ago
576 B
12
Indexable
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;
}
Editor is loading...