I had this interview question that need to recommend song
Question:
the historical data
User 1 has liked A, B, C, D
User 2 has liked A, C, D
User 3 has liked B, C, E
Now we have a user that liked C, D
As user1 and user 2 both like C and D, so their liked song will be recommend.
The system should recommend the user song A, B
( A should appear first, as user1 and user2 both liked A)
My solution (I didn't solve it):
Using Two hashmap
Map 1 <K, V> -> <User Name, likedSong list>
Loop through user and find the overlapping with input user's song
-> get the users that shared common interest
Map 2 <K, V> -> <Song Name, Count>
Loop through common users and check the repeat time of each song
I didn't have enough time to solve this problem, but I think the rest is to use PriorityQueue to get the order of the song.
Does anyone come up better idea?
Thank you