Walmart | Staff | Bengaluru | Rejected
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-04-16Added By Anonymous
Source: Link
Result : Awaiting
Interview asked me to design a popularity counter, having below functionalities -
•addUser(userId)
•removeUser(userId)
•incrementVote(userId)
•decrementVote(userId)
•getUserWithMostVote()
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 -
•Walmart is big company but they do not have any coding test and interview tool(such as HackerRank, CoderByte) for hiring developers.
•Interviewer has not turned-on video but asks interviewee to turn-on video and share the whole screen and not just the tab.
•My biased opinion - Seems like Interviewer was taking interview to reject candidate and not to take candidate, so he was giving inaccurate hints.