All problems
Snowball Sampling Count
Problem
Count the nodes collected by snowball sampling within k hops of a set of seeds.
Run a multi-source BFS from the seeds and count nodes whose distance is at most k. edges is a list of [u, v] pairs. Return the count as an integer.
Hint
Snowball sampling is just a BFS truncated at a hop limit.
Test cases
case 1
in: [4,[[0,1],[1,2],[2,3]],[0],2]
expected: 3
case 2
in: [4,[[0,1],[1,2],[2,3]],[0,3],1]
expected: 4
case 3
in: [4,[[0,1],[1,2],[2,3]],[0],0]
expected: 1
case 4
in: [3,[],[1],2]
expected: 1
Starter codePython
def snowball_sampling_count(n, edges, seeds, k):
# Your code here
pass4 test cases · run your code against them in the editor