Skip to content

Practice The Earliest and Latest Rounds Where Players Compete

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1900
LeetCode Problem

The Earliest and Latest Rounds Where Players Compete

Problem Statement

There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.). The tournament consists of multiple rounds (starting from round number 1). In each round, the ith player from the front of the row competes against the ith player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round. After each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order). The players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round. Given the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the latest possible round number in which these two players will compete against each other, respectively.

Source: The Earliest and Latest Rounds Where Players Compete on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 11, firstPlayer = 2, secondPlayer = 4
Output
[3,4]

# Example 2

Input
n = 5, firstPlayer = 1, secondPlayer = 5
Output
[1,1]

Constraints

2 <= n <= 28
1 <= firstPlayer < secondPlayer <= n

Related LeetCode Problems

Practice more problems similar to The Earliest and Latest Rounds Where Players Compete.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.