Feed order

Write code · Medium · §7.2 Permutations and combinations

topics holds the topics of the posts to put on a feed. topics[i] is the topic of post i. You arrange all the posts in a line, each exactly once, so that no two neighboring posts have the same topic.

Complete the function solution, which returns the number of such orders. Posts with the same topic are still different posts, so swapping two posts with the same topic gives a different order.

Function

solution(topics)

Constraints

Examples

topicsresult
['food', 'game', 'music']6
['news', 'news', 'news']0

Starter code

def solution(topics):
    answer = 0
    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.