A post spreading through shares

Write code · Challenge · §9.1 Following relationships

There are n users on a social network, numbered from 0 to n - 1. A record [a, b] in follows means that a follows b, so a post that b shares appears in a's feed.

Person start writes a post and shares it. Everyone whose feed shows this post reshares it. Complete the function solution, which returns the number of people, not counting start, whose feed shows this post at least once.

Function

solution(n, follows, start)

Constraints

Examples

nfollowsstartresult
6[[1, 0], [2, 0], [3, 1], [0, 4]]03
5[[1, 2], [3, 2], [0, 1]]23

Starter code

def solution(n, follows, start):
    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.