There is unique string indentifier for the card called bin(simple string). We need to implement 2 functions that store and lookup the bin with the details given the information. There were 3 parts to the problem:
Implement a class that has the following methods:
store():
Input: bin#: str, card_type: str, card_name: str, trust_score: Int (Trust score only for part 2 and 3)
Output: None
Description: given the informations, store the information in what they call cache (I used dictionary just like most of you would).
lookup():
Input: bin#: str
Output: card_type and card_name (whichever way you like. I suggest returning as list)
Description: Simple, given the bin return the information required
Part 1:
Easy. Just add the data and return as needed. Implement both methods pretty much. NOTE: If the store() is called with bin that is already there, we rewrite it for this part. This is the situtation where they add complexity in the following parts.
Part 2:
Now there is a trust score added in the store() input. We rewrite the bin information with the new input information if the intput trust score is >= to exisiting bin information. I just added the trust score in the dictionary values along with other information.
Part 3:
The last part. This is where you can have unique conditions. So when store() is called, the input can be None for card_type or card_name. Trust score is guaranteed as input parameter. Now if we already have the input bin present then we update the value if and only if the existing trust scrore of that value is lower or the previous value is None. They will ask you this in generic way and the solution to the whole part is to store tuple of each value with its trust score. So for example, for bin "x", we should now store the values [(card_type, trustscore when this was added), (card_name, trust_score when this was added.)} so in the following stores for this bin, we only update the value if the new trust_score is higher or if the previous value is None.
General notes: