All problems
Reverse Directed Edges
Problem
Reverse every edge of a directed graph and sort the result.
edges is a list of directed [u, v] pairs; the reversed graph contains [v, u] for each one and keeps duplicates. Return the reversed pairs sorted in ascending order. An empty input yields an empty list.
Hint
Swap the endpoints of every pair, then sort the list of swapped pairs.
Test cases
case 1
in: [[[0,1],[1,2]]]
expected: [[1,0],[2,1]]
case 2
in: [[]]
expected: []
case 3
in: [[[2,0],[0,1],[1,0]]]
expected: [[0,1],[0,2],[1,0]]
case 4
in: [[[1,1]]]
expected: [[1,1]]
Starter codePython
def reverse_directed_edges(edges):
# Your code here
pass4 test cases · run your code against them in the editor