Challenge 3: Calculate the Number of Nodes in a Given Graph Level

Given a graph, calculate the number of nodes in an undirected graph level.

Problem Statement

Implement a function that returns the number of nodes at a given level of an undirected graph in C++.

Try modifying the Breadth-First Traversal algorithm to achieve this goal.

To solve this problem, all the previously implemented data structures will be available to us.


An undirected graph represented as an adjacency list, a starting vertex, and the level whose number of nodes we need to find.


The number of nodes returned as a simple integer.

Sample Input


graph {0 - 1
       0 - 2
       1 - 3
       2 - 3
       3 - 5
       2 - 4

Level: 1

Sample Output


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