Algorithm/DS Problem#10: Implement a Logger
Sep 25, 2021
interface Logger {
/**
* When a process starts, it calls 'start' with processId and startTime.
*/
void start(String processId, long startTime);
/**
* When the same process ends, it calls 'end' with processId and endTime.
*/
void end(String processId, long endTime);
/**
* Prints the logs of this system sorted by the start time of processes in the below format
* {processId} started at {startTime} and ended at {endTime}
*/
void print();
}
We create a hashmap to store the start time of a pid. When we call end, we get the start time of the pid from the hashmap and append it into the heap.
Start: O(1)
End: O(logN)
Print: O(K)
Where k is the number of finished processes.