Pin Similarity and Themed Boards
Frequency: Reported
Pinterest boards contain collections of pins. Given a mapping from board IDs to their pins, compute a similarity score between one requested pin and every other pin that appears on a board with it.
Similarity is the number of boards on which the two pins co-occur.
python
boards = {
"board_1": ["a", "c", "d", "e", "f"],
"board_2": ["a", "c", "g", "i"],
"board_3": ["b", "d", "e", "j"],
"board_4": ["a", "c", "e"],
"board_5": ["b", "d"],
}For pin a, the expected scores are:
text
c=3, d=1, e=2, f=1, g=1, i=1Follow-up 1: top N
Update the function to return the top N pins in descending order of similarity. The source does not visibly specify how ties should be ordered.
Follow-up 2: single-theme boards
If the data instead includes meaningful board names, how might you find boards that are about a single theme?
python
boards = {
"dream vacations": ["a", "c", "d", "e", "f"],
"dinner ideas": ["r", "t", "p", "q"],
"bucket list": ["a", "c", "g", "i"],
"vacation destinations": ["b", "d", "e", "j"],
"vacations": ["a", "c", "e"],
"my likes": ["f", "s"],
"travel ideas": ["b", "d"],
"recipes": ["s", "r", "q"],
"favorites": ["a", "t", "d", "q"],
}No required algorithm, output format, or definition of "single theme" was supplied for this discussion follow-up.