Given two integers N1 and N2 where, N1 is the number of people in group 1 and N2 is the number of people in group 2. The task is to count the maximum number of 3-person teams that can be formed when at least a single person is chosen from both the groups.
Input: N1 = 2, N2 = 8
Team 1: 2 members from group 2 and 1 member from group 1
Update: N1 = 1, N2 = 6
Team 2: 2 members from group 2 and 1 member from group 1
Update: N1 = 0, N2 = 4
No further teams can be formed.
Input: N1 = 4, N2 = 5
Approach: Choose a single person from the team with less members and choose 2 persons from the team with more members (while possible) and update count = count + 1. Print the count in the end.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum and Maximum number of pairs in m teams of n people
- Given number of matches played, find number of teams in tournament
- Ways of dividing a group into two halves such that two elements are in different groups
- Maximum number of strings that can be formed with given zeros and ones
- Ways to form a group from three groups with given constraints
- Count of groups among N people having only one leader in each group
- Count of distinct XORs formed by rearranging two Binary strings
- Number of triangles formed from a set of points on three lines
- Number of triangles that can be formed with given N points
- Number of ways in which the substring in range [L, R] can be formed using characters out of the range
- Number of triangles formed by joining vertices of n-sided polygon with one side common
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Number of cycles formed by joining vertices of n sided polygon at the center
- Number of quadrilateral formed with N distinct points on circumference of Circle
- Print all possible strings of length k that can be formed from a set of n characters
- Sum of all numbers that can be formed with permutations of n digits
- All possible strings of any length that can be formed from a given string
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Sum of product of all subsets formed by only divisors of N
- N digit numbers divisible by 5 formed from the M digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.