Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-241

Graph Anomaly Score Lite

Problem

Score each node by the z-score of its degree: (degree - mean) / standard deviation.

When the standard deviation is zero, return zeros. Return the scores in node order as floats. n is the number of nodes and edges is a list of [u, v] pairs.

Hint

Degree z-scores highlight nodes whose connectivity is unusual for the network.

Test cases

case 1
in: [4,[[0,1],[1,2],[2,3]]]
expected: [-1,1,1,-1]
case 2
in: [3,[]]
expected: [0,0,0]
case 3
in: [4,[[0,1],[0,2],[0,3]]]
expected: [1.7320508075688772,-0.5773502691896257,-0.5773502691896257,-0.5773502691896257]
Starter codePython
import math
def anomaly_scores(n, edges):
    # Your code here
    pass

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