Challenge: Count the Number of Edges in an Undirected Graph

Given a graph, can you write a code to find the number of edges in a graph? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.

Problem Statement #

In this problem, you have to implement the numEdges() method to take an undirected graph as an input and find the total number of edges in the graph. An illustration is also provided below for your understanding:

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