Google | Screen Round | L4 | SWE | Selected
Question
Design a latency measuring server. You are given a method ping(), need to return the average latency of latest k latency values.
Proposed Solution to store latency items in array
SC - O(n)
TC - O(1)
Interviewer asked to optimise so proposed a queue solution to keep only last k elements in the queue
SC - O(k)
TC - O(1)
Interviewer did not ask to write the code
Follow up question
We need to measure the 95 percentile of latency. We need to remove top X elements from the average where X is 5% of k
Proposed solution to use min heap with x elements
Create heap on every call and update avergae
TC - O(klogK)
SC - O(k)
Interviewer asked to optimise so proposed TreeMap solution since we can get last X elements in linear time
TC - (K)
SC - O(K)
Only 5-8 minutes were pendiing, interviewer asked to code it up quickly
Completed the code, I was writing the inner traversal of tree map in order to get top X elements
Interviewer closed the document in between and said we are out of time now.
Verdict - Selected


