Ctrl K

Same Prizes, Different Tastes

Medium
Two players face n prizes, and each values them differently: prize i gives the first player first_values[i] points and the second player second_values[i] points. Both know both tables. The players take turns picking one prize each, the first player starting, until no prizes are left. Each player scores the prizes they took by their own values. Both play optimally. Return 1 if the first player ends with more points, -1 if the second player does, and 0 on a tie.
Example 1
first_values=[4, 1, 2], second_values=[1, 5, 3] → 1

The first player takes prize 1: it is worth only 1 to them, but that keeps it from the opponent, to whom it is worth 5. The second player takes prize 2 (3 points) and the first gets prize 0 (4 points). The score is 5 to 3.

Example 2
first_values=[2, 3], second_values=[3, 2] → 0

Whatever the first player takes, both end up with 3 points: a draw.

Example 3
first_values=[1, 1, 1], second_values=[6, 6, 6] → -1
Constraints
  • n == len(first_values) == len(second_values)
  • 1 ≤ n ≤ 10⁵
  • 1 ≤ first_values[i], second_values[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Middle Bag MediumPrices That Fade With Each Sale MediumStudios for Recording Sessions MediumJobs With a Cooldown MediumUp or Down for Every Post Medium
loading Python…
Input
first_values=[4, 1, 2], second_values=[1, 5, 3]
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.