Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-010

In/Out Degree Stats

Problem

Compute the out-degree and in-degree of every node in a directed multigraph with n nodes.

edges is a list of [u, v] pairs representing directed edges. Return a list of [out_degree, in_degree] pairs in node order; repeated edges count every time.

Hint

u contributes to out_degree, v contributes to in_degree.

Test cases

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

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