- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two integers N and M, N is the number of people in group 1, and M is the number of people in group 2. Our task is to create a *program to find the maximum number of 3-person teams formed from two groups.*

We will be creating teams of 3 people by selecting a person from these groups such that the maximum teams can be made. Each team must have at least one person from each group.

Let’s take an example to understand the problem,

**Input** − N = 5, M = 3

**Output** − 2

**Explanation** −

The teams will be as follows −

Team 1: Group 1 Member->2 ; Group 2 Member->1 Left in Group 1 = 3 ; left in Group 2 = 2 Team 2: Group 1 Member->2 ; Group 2 Member->1 Left in Group 1 = 1 ; left in Group 2 = 1 No more teams of 3 can be formed.

To solve this problem, we will create teams *taking 1 member form group with fewer persons and 2 members from the other group.* And **update the count of persons in each group.** Also, we will maintain a *count of teams and increment it after each team creation* until the team creation is possible.

**Program to find the maximum number of 3-person teams formed from two groups −**

#include <iostream> using namespace std; int CountTeams(int N, int M) { int teamCount = 0; while (N >= 1 && M >= 1 && N + M >= 3) { if (N > M) { N = N-2; M = M-1; } else { N = N-1; M = M-2; } teamCount++; } return teamCount; } int main() { int N = 5, M = 3; cout<<"The maximum number of 3-person teams is "<<CountTeams(N, M); return 0; }

The maximum number of 3-person teams is 2

- Related Questions & Answers
- Maximum number of groups of size 3 containing two type of items in C++
- Number of groups of magnets formed from N magnets in C++
- Number of Groups of Sizes Two Or Three Divisible By 3 in C++
- Count Number of Teams in C++
- Minimum and Maximum number of pairs in m teams of n people in C++
- Maximum factors formed by two numbers in Python
- Maximum length of rod for Qth person in C++
- Find maximum number that can be formed using digits of a given number in C++
- Minimum sum of two numbers formed from digits of an array in C++
- Finding maximum number from two arrays in JavaScript
- Program to find maximum number of balanced groups of parentheses in Python
- Maximum possible time that can be formed from four digits in C++
- Maximum Score Words Formed by Letters in C++
- Program to find maximum number of groups getting fresh donuts in Python
- Count all possible groups of size 2 or 3 that have sum as multiple of 3 in C++

Advertisements