Random Teams
You are given two integers n and m, representing the number of participants and the number of teams, respectively.
The n participants must be divided into exactly m teams such that every team has at least one participant. Once the teams are formed, every pair of participants within the same team becomes friends.
Your task is to calculate and return an array of two integers:
- The minimum possible total number of pairs of friends.
- The maximum possible total number of pairs of friends.
Example 1:
Input: n = 5, m = 1
Output: [10, 10]
Explanation:
There is only 1 team, so all 5 participants must be in it. The number of friend pairs is exactly 5 * 4 / 2 = 10. Both the minimum and maximum are 10.
Example 2:
Input: n = 3, m = 2
Output: [1, 1]
Explanation:
We must divide 3 participants into 2 teams. The only valid distribution is one team of 2 participants and one team of 1 participant. The team of 2 yields 1 pair of friends, and the team of 1 yields 0 pairs. Total pairs = 1. Both minimum and maximum are 1.
Now Your Turn!
Pick the correct output for the given inputInput: n = 4, m = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= m <= n <= 109