$\begingroup$

The problem is as follows, There is a restaurant which has N number of chairs each chair has a unique number written on it so the array of chairs is like [1,2,....N-1,N] , there are G number of groups who want to sit in the restaurant each group can have any number of persons (from 1 to N ) who have a certain preference for chair number they want to sit at now , only one person can sit on the chair obviously ,now i have to maximize the number of groups which can sit in the restaurant . what is the best way/algorithm to do this?

For example if N (number of chairs ) is 7 and Groups (G) who want to sit are 4 and preference for chairs are as follows group

1 -> 3,7

2 -> 5,6

3 -> 3,4

4 -> 1,2

So we can represent the data in the form of an array

so the maximum number of groups that sit are 3 (group 2,3,4) the required answer .