Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bob Jones lives with his family His family has members with member ID 0 t 0 Nit Bob Jones is the head of the family

Bob Jones lives with his family His family has members with member ID 0t0 Nit Bob Jones is the head of the family with member ID 0 His family has K 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 A is the parent of member B and if A had already received the salary, then B will keep the salary.
For example, in the given family hierarchy A->B->C, B is the parent of A and Cis the parent of B so if A receives the salary then it first goes to B, and then it goes to C but in case if Calready had received the salary then B will keep the salary of A and if in case B also received the salary already then. A will keep the salary
You are given two integers Nand K where N is the total number of members in the family and K is the total number of earning members in the family. You are given an array parents representing the parent's 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 -1 and therefore the parent array will always start with -1. You are given an array salary_order presenting the member IDs of all the earning members of the family inme order they receive the salary that is index O receives the salary first and then index 1 and so on.
Return an array containing the member ID of all members that keeps tge salary in the order they receive it.
Function description:
Complete the Solve() function provided that takes tge following arguments and retums the answer
N. Represents the total number of family members
K Represents the total number of earning members
parents[]: Represents the array of parents ie parents[i] represent the parent of an member
salary_order. Represents all the earning members of the family in the order they receive the salary
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing Code in a language where we don't provide boilerplate code.
* The first line contains integer N denoting the total number of family members
The second line contains integer K denoting the total number of earning members
* The third line contains N space-separated integers denoting the array of parents of each member.
The fourth line contains K space-separated integers denoting the array of earning members of the family in the order they receive the salary.
Output format:
Print the array of all the members that keep the salary in the order they receive it.
Sample input:
9
4
-101122344
8465
Sample output:
0132

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What have been the keys to Nokias global strength?

Answered: 1 week ago