Viewers With Matching Recent Watches
Asked at Netflix
Reported by the problem's creator, not verified
You are given a ViewingHistory class built from histories, a dictionary mapping each user id to that user's watch history: movie ids in the order the user watched them, oldest first. A movie may appear more than once in one history.
A user's recent movies for k are the distinct movies among the last k entries of their history. A shorter history uses all its entries, and an empty history gives the empty set. Order and repeats do not matter.
Histories never change after construction.
Examples
Example 1
Input: init =
[{"cy":[2,4,3,7],"ann":[1,2,3,4],"bob":[9,3,4,2],"dee":[5,6],"eve":[6,5],"fay":[4,4,3,2],"gus":[8]}], operations =[["groups",[3]],["groups",[2]],["groups",[1]],["groups",[10]]]Output:
[[["ann","bob","fay"],["dee","eve"]],[["dee","eve"]],[["bob","fay"]],[["dee","eve"]]]Explanation: With
k = 3,ann,bobandfayall have the recent set {2, 3, 4} despite different orders and a repeat, anddeeandeveboth have {5, 6};gusmatches nobody. Fork = 2onlydeeandevestill match, fork = 1onlybobandfayshare the movie 2, and fork = 10the full histories again match onlydeeandeve.