Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,134 views
in Online Assessments by Expert (34,270 points) | 1,134 views

1 Answer

0 like 0 dislike

Ouestion 2:

 

Path MEX
You are given a rooted tree having N nodes. A tree is connected undirected graph with N-1 edges. Here root nodes 1. Each nodes has some integer value val, associated with it.

 

Task
For each each node i(1<=i<=N), print MEX of the path values form the root node to node i.

 

Notes

 

  • Assume 1-based indexing
  • The MEX of an array is equal to the samllest positive iinteger that is not present in array. For example, MEX(1, 2, 4, 2, 3, 6, 7)=5.

 

Sample input

 

1 
6
1 3 2 2 4 2
1 1 2 2 5

 

Sample Output

 

2 2 3 4 2 5
by Expert (34,270 points)