I interviewed for 45 minutes and got one question. I'd solved it before, but I still wrote two bugs. Luckily I caught and fixed both while testing, and it passed in the end. Thanks to the interviewer for going easy on me.
The question was the one that comes up most often for the phone screen: design a customer satisfaction (CSAT) tracking class. Scores are fixed in the range 1 to 5.
__init__(self, window_size: int): initialize the size of the time window.record(self, conversation_id: str, score: int, timestamp: int): record a conversation's unique ID, its score, and a strictly increasing timestamp.get_average(self, current_time: int): return the average of all scores within the current active window, rounded to two decimal places (round(x, 2)).
Follow-up 1: support updates.
update(self, conversation_id: str, score: int): if the conversation is still inside the active window, update its score; if it has already expired, this is a no-op. Note: updating does not change the original timestamp or ordering.
Follow-up 2: compute a percentile.
- Given
p: int, find the score of the conversation at that percentile (e.g. p50 / median).
Discussion
Loading comments…