Dsa
Graphs Bfs
Warm-up
Viral Meme Spread
A meme starts with one person on a social network. Every hour, everyone who knows the meme shares it with all their direct friends who haven't seen it yet. Given the network connections, the starting person ID, and a time limit T (in hours), calculate the total number of people who will have seen the meme after T hours (including the starter).
Example:
Input:
5 4
0 1
0 2
1 3
3 4
0 1
Output:
3
(At T=0: {0}. At T=1: {0, 1, 2}. Total 3.)
Key concepts
graphsbfsreachability
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now