• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 20, 2023 |1.3K Views
PROBLEM OF THE DAY: 19/10/2023 | Level of Nodes
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Tree but will also help you build up problem-solving skills.

In this problem, we are given, an integer X and an undirected acyclic graph with V nodes, labeled from 0 to V-1, and E edges, Our task is to find the level of the node labeled as X.

The level is the minimum number of edges you must travel from node 0 to some target.

If there doesn't exist such a node that is labeled as X, return -1.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/level-of-nodes-1587115620/1

Solution Function Link: https://ide.geeksforgeeks.org/online-cpp-compiler/83354b3e-f878-468a-ab3c-15be10a5bb47