Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-101

Preferential Attachment Score

Problem

Compute the preferential attachment link prediction score of nodes u and v: the product of their degrees in an undirected graph.

Return an integer. edges is a list of [u, v] pairs, and repeated edges count each time.

Hint

Highly connected nodes are expected to connect to each other under preferential attachment.

Test cases

case 1
in: [4,[[0,1],[1,2],[2,3]],0,3]
expected: 1
case 2
in: [4,[[0,1],[0,2],[0,3]],0,1]
expected: 3
case 3
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]],0,1]
expected: 9
case 4
in: [3,[],0,1]
expected: 0
Starter codePython
def preferential_attachment(n, edges, u, v):
    # Your code here
    pass

4 test cases · run your code against them in the editor