Problem Statement
Amazon Games is organizing a tournament of pair games where two teams of two players each compete against one another.
There are two groups, group1
and group2
, each of size n
. The skill levels of the i
th players of the groups are group1[i]
and group2[i]
, respectively. For each pair of indices (i, j)
where 0 <= i < j < n
, the pair of players (group1[i], group1[j])
competes in the pair game with (group2[i], group2[j])
.
The winner of the game is:
group1
ifgroup1[i] + group1[j] > group2[i] + group2[j]
group2
ifgroup1[i] + group1[j] < group2[i] + group2[j]
If the sums are equal, there is no winner.
Task
Write a function countGamesWonByGroup1(group1, group2)
that computes the number of games won by group1
. Since the answer can be large, return the result modulo 10^9 + 7.
Function Signature
def countGamesWonByGroup1(group1: list[int], group2: list[int]) -> int:
pass
Input
group1
: A list of integers representing the skills of the players in group1.group2
: A list of integers representing the skills of the players in group2.
Output
- An integer representing the number of games won by
group1
, modulo 1000000007.
Example
Example 1:
Input:
n = 3
group1 = [1, 2, 3]
group2 = [3, 2, 1]
Output:
1
Explanation:
The pairs and outcomes are:
(0, 1)
->group1 = [1, 2]
,group2 = [3, 2]
, winner =group2
(0, 2)
->group1 = [1, 3]
,group2 = [3, 1]
, no winner(1, 2)
->group1 = [2, 3]
,group2 = [2, 1]
, winner =group1
group1
wins one game, so the answer is 1
.
Example 2:
Input:
n = 3
group1 = [1, 3, 2]
group2 = [1, 3, 2]
Output:
0
Explanation:
All skills of both groups at respective indices are equal, so no one wins any games.
Constraints
- 2 <= n <= 100000
- 1 <= group1[i], group2[i] <= 1000000000
Notes
- Iterate through all possible pairs
(i, j)
where0 <= i < j < n
to calculate the outcome for each game. - Use modulo 1000000007 to avoid integer overflow.
- Optimize the solution to handle large values of
n
efficiently.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.