1-hour interview, focused on concurrency. The interviewer has a bachelor's in CS from MIT.
The role is SWE, AI Infra, and it requires a bachelor's plus 3 years of YOE.
The problem: send an HTTP batch request to /get?keys=key1,key2 every 100ms. You need to think about how to schedule the 100ms callback, and how to store the keys waiting to be sent along with the callback for each key.
Endpoint: /get?keys=key1,key2,...
Response: { "key1": 123, "key2": abs }
Provided API:
http_get_request(url, callback)
callback(response: dict)
set_timeout(callback, ms) # schedule callback at ms
def main():
start_fetch("foo", cb1) # t = 0
start_fetch("bar", cb2) # t = 30ms
start_fetch("foo", cb3) # t = 70ms
start_fetch("foo", cb4) # t = 120ms
Make sure http_get_request is only called twice. The first call comes back and calls cb1, cb2 and cb3. The second call then calls cb4.
def start_fetch(key, callback):
# TODO: implement this
I used global variables: keys = [], callbacks = defaultdict(list), scheduled = False, and added two functions, batch_fetch and handle_response. scheduled just tracks whether http_get_request has been called yet; if it hasn't, I call set_timeout(batch_fetch, 100). Keys get appended to keys, and the callback gets appended to callbacks[key]. Then http_get_request(endpoints, lambda response: handle_response(response, callbacks)).
The question shouldn't be that hard, it's just that I had never written a concurrency problem before. The interviewer gave me a lot of hints before I managed to finish in 45 minutes. After that was Q&A.
I asked: what does the org tree look like? Answer: head of engineering -> 6 PMs, 40 SWEs, 6-7 teams.
Update: I got the rejection the next day.
Discussion
Loading comments…