FastPrepFastPrep
Problem Brief

Group 1 Win Count

OA

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 Description

Complete the function group1WinCount in the editor.

group1WinCount takes the following arguments:

  1. 1. int g1[n]: The skills of the players of group1
  2. 2. int g2[n]: The skills of the players of group2

Returns

int: The number of games won by group1 modulo 109 + 7.

1Example 1

Input
g1 = [1, 2, 3], g2 = [3, 2, 1]
Output
1
Explanation

Suppose 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

Limits and guarantees your solution can rely on.

  • 2 ≤ n ≤ 105
  • 1 ≤ g1[i], g2[i] ≤ 109
public int group1WinCount(int[] g1, int[] g2) {
    // write your code here
}
Input

g1

[1, 2, 3]

g2

[3, 2, 1]

Output

1

Sign in to submit your solution.