Hello all, Just wanted to share my recent experience for google phone screen round
Time: 45 minutes
Question: i dont remember exact wording but the structure is as follows:
Q) Design a system/data structure to given the user Top N Most Recently Searched Items
My thought process:
- After listening to TopN i said we can used Heap, they hinted/clarified it is "recently searched and not frequently"
- So then i thought more and got the idea of ordered dictionary based on 146. LRU Cache
there is a max size n, and the user can search something
**for the search -> **
- we have to return the top N elements from the dictionary
**for the insert -> **
- you can update the key:value and move to one end for the frequency.
- if it is a new key, check len + 1 > n size and if it goes oversize -> pop element and then insert new one (maintain the ordering)
was asked followups questions like
- time and space complexity of approach 1
- if you dont use ordered dict then how would you solve it?
* i suggested -> dictionary + linked list [ with prev and next pointers], dictionary for key = search item and values for linked list node item
* insert and one end
* remove at other end
* if duplicate key -> move to the insert end
* all 3 requireing to play with prev and next pointers
hope this helps. I will try to answer questions in the comments as best possible.