Challenge 5: Count the Number of Edges in an Undirected Graph

In this lesson, you will figure out if it's possible to count the total number of edges in a graph.

Problem statement

You have to implement the int numEdges(Graph g) function, which takes an undirected graph and computes the total number of bidirectional edges. An illustration is also provided for your understanding.

Input

The input is an undirected graph.

Output

It returns the total number of edges in the graph.

Sample input

graph = {
    0 - 2
    0 - 5
    2 - 3
    2 - 4
    5 - 3
    5 - 6
    3 - 6
    6 - 7
    6 - 8
    6 - 4
    7 - 8
}

Sample output

11

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.