Group 1 Win Count
Learn this problemProblem 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 g1 and g2 of size n each. The skill levels of the ith players of the groups are g1[i] and g2[i]. For each pair of indices, (i, j) (0 ≤i < j < n), the pair of players (g1[i], g1[j]) compete in the pair game with (g2[i], g2[j]).
The winner of the game is group1 if g1[i] + g1[j] > g2[i] + g2[j], and vice-versa.
Given g1, and g2, find the number of games group1 will win. Since the answer can be large, report it modulo 109 + 7.
Function
group1WinCount(g1: int[], g2: int[]) → int
Complete the function group1WinCount in the editor.
group1WinCount takes the following arguments:
- 1.
int g1[n]: The skills of the players of group1 - 2.
int g2[n]: The skills of the players of group2
Returns
int: The number of games won by group1 modulo 109 + 7.
Examples
Example 1
g1 = [1, 2, 3]g2 = [3, 2, 1]return = 1Suppose n = 3, g1 = [1, 2, 3], and g2 = [3, 2, 1].
[Table showing: Pair | group1 | group2 | Winner (0, 1) | [1, 2] | [3, 2] | group2 (0, 2) | [1, 3] | [3, 1] | - (1, 2) | [2, 3] | [2, 1] | group1]
group1 wins one match so the answer is 1.
Constraints
- 2 ≤ n ≤ 105
- 1 ≤ g1[i], g2[i] ≤ 109
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026