Amazon | Onsite | Total groups of friends
Anonymous User
3095
  • Given n friends and their friendship relations, find the total number of groups that exist. And the number of ways of new groups that can be formed consisting of people from every existing group.
    * If no relation is given for any person then that person has no group and singularly forms a group. If a is a friend of b and b is a friend of c, then a b and c form a group.
    *
    * Input : Number of people = 6
    * Relations : 1 - 2, 3 - 4
    * and 5 - 6
    * Output: Number of existing Groups = 3
    * Number of new groups that can
    * be formed = 8
    *
    *
    * Input: Number of people = 4
    * Relations : 1 - 2 and 2 - 3
    * Output: Number of existing Groups = 2
    * Number of new groups that can
    * be formed = 3
    */
Comments (7)