#1900

The Earliest and Latest Rounds Where Players Compete

specialist · 970 · lc hard +32 · failed · 72.7% accepted · 517 likes · top 82%

Description

In a tournament, n players are arranged in a row numbered 1 to n. Each round the i-th from the front plays the i-th from the back; the middle player auto-advances when n is odd. Winners are re-sorted by their original numbers.

Two specific players firstPlayer and secondPlayer always beat everyone else but each other. You decide the outcomes of all other matches.

Return [earliest, latest] — the earliest and latest rounds in which the two can face each other.

Example 1:

Input: n = 11, firstPlayer = 2, secondPlayer = 4
Output: [3,4]
Explanation:
One possible scenario which leads to the earliest round number:
First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Second round: 2, 3, 4, 5, 6, 11
Third round: 2, 3, 4
One possible scenario which leads to the latest round number:
First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Second round: 1, 2, 3, 4, 5, 6
Third round: 1, 2, 4
Fourth round: 2, 4

Example 2:

Input: n = 5, firstPlayer = 1, secondPlayer = 5
Output: [1,1]
Explanation: The players numbered 1 and 5 compete in the first round.
There is no way to make them compete in any other round.

Code

1
2
3