The interview process involved designing a popularity counter with the following functionalities:
I initially proposed a brute-force solution using a Map to track vote counts per user and return the userId with the maximum votes. I then suggested using a TreeMap with voteCount as the key and a List of users as values, allowing retrieval of the user(s) with the highest vote count.
However, the interviewer asked for a solution that achieved constant time O(1) for all function calls. I struggled to find an alternative approach even after spending 30-40 minutes.
The interviewer clarified that the internal operations of data structures could be treated as constant, which I found questionable as the time complexity of various internal data structure operations cannot be disregarded.
Observations from the interview: