Phone Screen: problem similar to leetcode 815.
Virtual onsite Interview 1 (DS):
Imagine each Pin on Pinterest has a "trending score" associated with it. You're asked to build a feature which keeps track of all the Pins a user has seen in the last week and at any given time shows the top trending Pin that has been viewed by this user. (ie. Of all the Pins user123 has viewed in the last 24 hours, let them know which one is the most trending now).
Example
A Pin score tracker records scores of Pins that a user has seen and keeps track of the highest scored pin that was viewed in the last week. (note: this question could be modified to the last 5 minutes, 5 hours or 5 days if we add a timestamp component)
Questions
Implement add_new_pin which adds any new Pins viewed to the running list of Pins
pin_scores = [{"981292206280418755" : 50},
{"981292206280418756" : 35},
{"981292206280418757" : 91},
{"981292206280418758" : 92},
{"981292206280418759" : 3},
{"981292206280418760" : 88},
{"981292206280418761" : 34},
{"981292206280418762" : 9},
{"981292206280418763" : 77},
{"981292206280418764" : 55}]
-
Implement remove_expired_pin which ensures the top scoring pin we are returning is not outside our time range. (In the above example we did not include a timestamp but the candidate can check the top Pin's time, compare it against the current time, and remove it if needed)
-
Implement get_top_scoring_pin to get the top scoring pin in the data set. For simplicity let's imagine it's the most recent 10 pins. In the example data above, this should return pin_id "981292206280418758"
-
Can you discuss the runtime complexity of each of the above operations for this structure
Discussion
Loading comments…