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
- The length of
topicsis from 1 to 7. - Each topic is a string of lowercase English letters, with a length from 1 to 10.
Examples
| topics | result |
|---|---|
['food', 'game', 'music'] | 6 |
['news', 'news', 'news'] | 0 |
Starter code
def solution(topics):
answer = 0
return answerSolve 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.