Challenge: Calculate the Number of Nodes in a Graph Level

Solve the challenge to calculate the number of nodes in a graph at a given level.

Problem statement

Implement a function that returns the number of nodes at a given level starting from a root node of a directed graph.

Note: 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.

Input

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

Output

The number of nodes returned as a simple integer.

Sample input

Graph:

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