Result : Awaiting
Interview asked me to design a popularity counter, having below functionalities -
I proposed the brute-force solution with Map to keep count of votes per user and return the userId having maximum votes.
Then I moved to other solution of using TreeMap of voteCount as key and List of users as values so that I can retrive the user(s) having max votes.
But interview asked me how we can achieve constant time O(1) for all the function calls available.
I could not find any other way even after thinking 30-40 minutes.
Then he clarified the internal operations of DS can be treated as constant, which looks off to me as we can't just write-off the time complexity of various operations of internal DS used.
Things noted during interview -