1

Node Level

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
85%

Problem Statement
Suggest Edit

Given a binary tree having N nodes and an integer M you have to return the level of node M.

Note: Consider root to be at level 1.

Input format :
The first line contains a single integer T representing the number of test cases.      
The T-test cases are as follows:

Line 1: Elements in the level order form (separated by space). If any node does not have a left or right child, take -1 in its place
Line 2: Integer M
Output format :
For each test case, print the level of the node M in the binary tree
The output of each test case should be printed in a separate line.
Constraints:
1 <= T <= 100
1 <= N <= 3000
1 <= nodeVal <= 10^9

Time Limit: 1 sec
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Sample Input:
1 
1 2 3 -1 -1 -1 -1
3
Sample Output:
2   
Want to solve this problem? Login now to get access to solve the problems