Google Phone Screen
API Responses
Header:
Set-Cookie: auth=xxx; content=xxx; Secure; r/n
Set-Cookie: auth=xxx; content=xxx; r/n
Body:
...
Create a program that allows users to fetch cookie by their key (first attribute) and get all attributes associated with that key.
Secure cookies that occurred more than 10 minutes ago should not be returned.
Solution:
Initially went with LRU cache which resulted in loss of time before realizing that a dict of dict (for cookies and their attributes) plus a deque (with tuples of cookie_key and timestamp) was enough.
I had to come up with my own way of recording time of collected cookie and had to use timestamps to eject expired cookies (sliding window).
I think my approach would've worked, but I ran out of time.
EDIT: For anyone in the future, upon reflection, the approach is indeed correct but there will be no timestamps given, interviewer wanted me to come up with my own approach so I used datetime.now().
This means to check if a secure cookie should be ejected you do:
# Assuming time is in seconds
if self.cookie_cache[cookie_key].timestamp < datetime.now() - (60 * 10) and self.cookie_cache[cookie_key].is_secure:
del self.cookie_cache[cookie_key]This is a very difficult question, not the implementation, but understanding how to process the data. Do also note that I had to parse the input manually, break the strings with split.
I think it's very difficult to finish this problem in the given time anyway.


