Similar posts

Write code · Medium · §7.2 Permutations and combinations

posts holds the hashtag list of each post. posts[i] is the tag list of post i, and the same tag may appear more than once in one post. The tags that two posts both have are called their common tags.

Complete the function solution, which finds the two different posts with the largest number of distinct common tags and returns their post numbers as a list [i, j] (i < j). Two posts with no common tags count as 0. If several pairs tie for the largest number, return the one with the smallest i, and among those, the one with the smallest j.

Function

solution(posts)

Constraints

Examples

postsresult
[['ai', 'music'], ['food', 'travel'], ['music', 'ai', 'art']][0, 2]
[['game', 'live'], ['game', 'news', 'live'], ['news'], ['live', 'game', 'news']][1, 3]

Starter code

def solution(posts):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.