Hi, I recently interviewed for Microsoft. Following question was asked to me in their design round. I was interviewing for Azure Core Team
Below question was pasted in the codility editor and had to write the code for it.
Q) Create a Resource Pool, Basically you should implement a getResource and a releaseResource function.My solution after getting hints from the interviewer :
Create a class ResourcePool where we can eagerly load all the resources into a List of fixed pool size.
We can then remove a particular resource and allocate it to user as and when needed ( getResource )
And add back the resource to the pool ( releaseResource )
Later, the interviewer asked me what would be the edge cases and how would I make this solution thread safe.
Added edge case and added a synchronized block as well. Later, he asked me how is synchronization implemented internally?
I don't think I answered this well. I mentioned about the wait() , notify(), yeild() and join() methods.
Later the interviewer asked:
How would you handle a scenario when a particular user asks for resources over his allotted pool size?
Initially, I proposed a solution where we can sort of keep track of how many extra resources we have allocated to the user and later bill them accordingly, but interviewer said what if your system has a resource crunch and you cannot create more resources?
I answered we can have a timestamp variable in the Resource Object and on the basis of that we can check which is the least recently accessed resource and we can give that resource to the user
I was nervous through out as I have never solved such questions ( this was my first ever LLD / Multi Threading round) and the Interviewer also gave lots of hint to me.
Don't think the interviewer was satisfied by my approach.
Any ideas on how we should proceed for such problems?