All problems
Line Graph Degree Sequence
Problem
Compute the degree of every edge when edges become nodes of the line graph.
In a simple undirected graph, an edge u-v is adjacent in the line graph to every other edge at u or at v, so its degree is deg(u) + deg(v) - 2. Return the degrees in input edge order. n is the number of original nodes and edges is a list of [u, v] pairs.
Hint
Subtracting 2 removes the edge itself, counted once at each endpoint.
Test cases
case 1
in: [4,[[0,1],[1,2],[2,3]]]
expected: [1,2,1]
case 2
in: [4,[[0,1],[0,2],[0,3]]]
expected: [2,2,2]
case 3
in: [3,[[0,1],[1,2],[2,0]]]
expected: [2,2,2]
case 4
in: [2,[[0,1]]]
expected: [0]
Starter codePython
def line_graph_degree_sequence(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor