Smallest Missing Genetic Value in Each Subtree
In a family tree rooted at 0 and consisting of n nodes numbered 0 to nā1, you are given a 0-indexed integer array named parents, where parents[i] represents the parent for node i. Since node 0 is the root, parents[0] = ā1.
Additionally, there are 10^5 genetic values, each represented by an integer in the inclusive range [1, 10^5]. You are provided with another 0-indexed integer array named nums, where nums[i] is a distinct genetic value for node i.
The task is to determine and print an space separated array named ans of length n, where ans[i] denotes the smallest genetic value that is missing from the subtree rooted at node i.
The subtree rooted at a node x contains node x and all of its descendant nodes.
I want to discuss a solution
Help me solve this
Give more examples
What's wrong with my code?
How to use 'for loop' in javascript?