Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Salary day Bob Jones lives with his family. His family has N members with member IDs O to N - 1 . Bob Jones is
Salary day
Bob Jones lives with his family. His family has members with
member IDs to Bob Jones is the head of the family with
member ID His family has number of earning members. Every
month, each earning member receives their salary in a particular
order and then gives it to their parent; the parent in turn gives the
salary to their parents, and so on The salary will be given to the
highest member of the family hierarchy. If member is the parent of
member and if A has already received the salary, then will keep
the salary.
For example, in the given family hierarchy is the parent of
A and is the parent of so if A receives the salary, then it first
goes to and then it goes to but in case if already had received
the salary then will keep the salary of A and if in case also
received the salary already then, A will keep the salary.
You are given two integers, and where is the total number of
members in the family, and is the total number of earning members
in the family. You are given an array parents representing the parents
member ID where the index represents the child's member ID As
Bob Jones is the head of the family, he will have no parent that will
be represented by and therefore, the parent array will always start
with You are given an array salaryorder representing the member
IDs of all the earning members of the family in the order they receive
the salary that is index recelves the salary first and then index and
so on
Return an array containing the member ID of all members that keep
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started