Count the shortest chains
transcript
A social app passes introductions. A chain goes friend to friend. How many shortest chains exist?
The start has one way to be reached. Each level is one more hop. Count the ways at every person.
People one, two and three have one way each. Person four is two hops out. It adds the ways of all three neighbours.
A neighbour one hop closer adds its ways. A neighbour at the same level adds nothing. Add, and never overwrite.
A private person accepts a request. But passes nothing on, so two chains remain.
The number of chains can be huge. So the problem asks for a modulus. Reduce after every addition.
In the interview, say who may pass a request on. Say which counts need a modulus. And say what the last line returns.
Each person is queued once. Each friendship is read twice. So the cost is linear.
Add the ways from one hop closer. Private people only end a chain. Full breakdown in the lecture.