Microsoft Interview Questions: Number of Employees in the factory | Yaozong's Blog
You have a log file containing the entering and leaving time of each employee in the factory. Given a query time (a floating number), write a function to count how many employees in the factory.
File Format:
001 0.14 0.15
002 0.32 0.60
003 0.25 0.80
…
…
Question 1: Assume that the log file is too large to fit into memory, write a function with the following signature to return the count.
Read full article from Microsoft Interview Questions: Number of Employees in the factory | Yaozong's Blog
You have a log file containing the entering and leaving time of each employee in the factory. Given a query time (a floating number), write a function to count how many employees in the factory.
File Format:
001 0.14 0.15
002 0.32 0.60
003 0.25 0.80
…
…
Question 1: Assume that the log file is too large to fit into memory, write a function with the following signature to return the count.
Question 2: If the data can fit into memory and you are allowed to do preprocessing, reduce the time complexity of query to O(logn).
There are two O(logn) solutions, considering both cases. For each case, first design the data structure storing the preprocessed results, and then write both preprocess and query function.
Solution 1: Binary Search
Solution 2: Store the curve (e.g., the skyline problem)
Followup: what should you do if we need to improve the time complexity of Query function to O(1).
Answer: 1) for all floating numbers (2^32 number), pre-compute their results and save them in the lookup table.
2) quantize the curve into different bins and store the histogram for lookup. It only approximates the solution but significantly saves the space compared to 1).
2) quantize the curve into different bins and store the histogram for lookup. It only approximates the solution but significantly saves the space compared to 1).