Doubt in the question

how to reach to a given level???

You can reach a particular level using DFS as well as BFS. For the technique using DFS, let’s consider your recursive funtion to explore a vertex is solve (v). In this function, pass an extra paramter count which is initally passed as 0 for root and pass count + 1 for each of the children of a particular node v. Now, to check if you have reached level k, just check if count == k

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.