Help me in this question

There are n private bankers and m participants.
Assume for each participant, they want to meet a number of private bankers and similarly, for each private banker they want to recruit a number of participants. However, only one-on-one meetings are possible. So for each session, one participant can only meet one banker.
Ifwe have a list of preferences from participants and private bankers, how many sessions are needed in order to fulfil everyone’s preferences?
Every banker and participant must have at least one preference.
Input format
The first line relates to the private bankers, and the second line relates to the participants.

The first integer in each line is the number of bankers/participants.

The subsequent integer input is the preference of bankers/participants, the preference of each person is separated by ,.

For example:

2 1&2,2
2 1,2
The first line of input means that there are two private bankers. The preference of banker 1 is to meet participants 1 & 2, and the preference of banker 2 is to meet participant 2 only.

The second line of input means that there are two participants. The preference of participant 1 is to meet banker 1 only, and the preference of participant 2 is to meet banker 2 only.
Output format
An integer that is the minimum number of sessions required to fulfil everyone’s preferences.
Input
2 1,2&3
3 1,2,2
Output
2

i.e. In the first session, banker 1 will meet with participant 1 (fulfilling banker 1’s preference and participant 1’s preference) and banker 2 will meet with participant 2 (fulfilling banker 2’s first preference and participant 2’s preference). Another session is needed to fulfil banker 2’s second preference and participant 3’s only preference. In the second session, banker 2 will meet with participant 3 (fulfilling banker 2’s second preference and banker 3’s preference) and banker 1 will meet with participant 2. After two sessions, everyone’s preferences have been fulfilled.

Example 2
Input
3 1,1,1
3 3,1,1
Output
3

i.e. There are many ways to arrive at this solution. This is just one of them. In the first session, banker 1 will meet with participant 1 (fulfilling banker 1’s preference), banker 2 will meet with participant 2 and banker 3 will meet with participant 3. In the second session, banker 2 will meet with participant 1 (fulfilling banker 2’s preference), banker 3 will meet with participant 2, and banker 1 will meet with participant 3 (fulfilling participant 3’s preference). This leaves banker 3, participant 1, and participant 2’s preferences. So in the third session, banker 3 will meet with participant 1 (fulfilling banker 3’s preference and participant 1’s preference), banker 1 will meet with participant 2 (fulfilling participant 2’s preference), and banker 2 will meet with participant 3. After three sessions, everyone’s preferences have been fulfilled.
Just give me hint ,I will solve myself

Create a list that who want to meet whom:

like this:


Now approach,
In my opinion use trees, like this

3 1,2&3,3
3 1,2,3
Answer should be 2 but here after making tree ,we are getting maximum branch as 1
Plz look into this test case.

What i said is that, the answer can not be less than the maximum number of branches, but it can be more than that. Use bruteforce to check that

Can u give psuedo code ,I am not getting how to implement logic in code.

hello @Bhawna what issue you are facing ?
and what is the question name and where you are trying to solve this ?

Question—>There are n private bankers and m participants.
Assume for each participant, they want to meet a number of private bankers and similarly, for each private banker they want to recruit a number of participants. However, only one-on-one meetings are possible. So for each session, one participant can only meet one banker.
Ifwe have a list of preferences from participants and private bankers, how many sessions are needed in order to fulfil everyone’s preferences?
Every banker and participant must have at least one preference.
Input format
The first line relates to the private bankers, and the second line relates to the participants.

The first integer in each line is the number of bankers/participants.

The subsequent integer input is the preference of bankers/participants, the preference of each person is separated by ,.

For example:

2 1&2,2
2 1,2
The first line of input means that there are two private bankers. The preference of banker 1 is to meet participants 1 & 2, and the preference of banker 2 is to meet participant 2 only.

The second line of input means that there are two participants. The preference of participant 1 is to meet banker 1 only, and the preference of participant 2 is to meet banker 2 only.
Output format
An integer that is the minimum number of sessions required to fulfil everyone’s preferences.
Input
2 1,2&3
3 1,2,2
Output
2

i.e. In the first session, banker 1 will meet with participant 1 (fulfilling banker 1’s preference and participant 1’s preference) and banker 2 will meet with participant 2 (fulfilling banker 2’s first preference and participant 2’s preference). Another session is needed to fulfil banker 2’s second preference and participant 3’s only preference. In the second session, banker 2 will meet with participant 3 (fulfilling banker 2’s second preference and banker 3’s preference) and banker 1 will meet with participant 2. After two sessions, everyone’s preferences have been fulfilled.

Example 2
Input
3 1,1,1
3 3,1,1
Output
3

i.e. There are many ways to arrive at this solution. This is just one of them. In the first session, banker 1 will meet with participant 1 (fulfilling banker 1’s preference), banker 2 will meet with participant 2 and banker 3 will meet with participant 3. In the second session, banker 2 will meet with participant 1 (fulfilling banker 2’s preference), banker 3 will meet with participant 2, and banker 1 will meet with participant 3 (fulfilling participant 3’s preference). This leaves banker 3, participant 1, and participant 2’s preferences. So in the third session, banker 3 will meet with participant 1 (fulfilling banker 3’s preference and participant 1’s preference), banker 1 will meet with participant 2 (fulfilling participant 2’s preference), and banker 2 will meet with participant 3. After three sessions, everyone’s preferences have been fulfilled.

This question came in my college contest weekly contest.

bhawna did u implement what i told u. please let me know here…

Yes and It passed all test cases

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

can you tell me what is the approach to solve this question.

how to use the bruteforce because i did the above part, how to implement brute force so that if more maximum branches is the answer.

Mam, could u plz tell me that approach. @akkipoonia

@akkipoonia what implementation did you tell ??
I don’t see any implementation idea from you in this post
If you explain in this post it will be very helpful.