# Create minimum groups required to grant privileges users

Problem

There are multiple users who require privileges to perform a certain task. A user must not be granted more privileges than needed. Two or more groups can contain some common privileges.

e.g.

``````    user1 -> p1 p2 p3
user2 -> p1    p3
user3 ->    p2
``````

We need to create a minimum number of groups with privileges so that we can assign users to that group.

e.g.

``````    group1 (p1 p3) -> user1, user2
group2  (p2)   -> user1, user3
``````

Some test cases
case 1:

Input:

``````    user1 -> p1
user2 ->    p2
user3 ->        p3
user3 ->           p4
``````

Output:

``````    group1(p1) -> user1
group2(p2) -> user2
group3(p3) -> user3
group4(p4) -> user4
``````

case 2 :
Input:

``````    user1 ->     p2  p3  p4
user2 ->     p2  p3  p4
user3 -> p1  p2  p3
user4 ->     p2  p3
``````

Output:
solution1

``````    group1(p1) -> user3
group2(p2,p3) -> user1,user2,user3,user4
group3(p4) -> user1, user2
``````

solution2:

``````    group1(p1) -> user3
group2(p2,p3,p4) -> user1,user2
group3(p2,p3) -> user3, user4
``````