Ctrl K

When the Favourites Meet

Hard
A tournament has players players. They stand in a row and are numbered 1 to players by their original place in the row. The tournament runs in rounds, starting from round 1. In each round the i-th player from the front of the row plays the i-th player from the back, and the winner advances. If the number of players is odd, the one in the middle advances without playing. After the round the winners line up again in increasing order of their original numbers. Players first and second are the favourites: each of them beats anyone else until the two face each other. Any other match can go either way, and you choose its outcome. Return an array of two numbers: the earliest and the latest round in which the favourites can meet.
Example 1
players=6, first=1, second=3 → [2, 3]

Round one pairs 1–6, 2–5 and 3–4. If 1, 2 and 3 win, round two pairs 1–3, which is the earliest option. If 5 wins instead, the row is 1, 3, 5 and the stars meet only in round three.

Example 2
players=7, first=2, second=6 → [1, 1]

The second player from the front and the second from the back meet right in round one.

Example 3
players=2, first=1, second=2 → [1, 1]
Constraints
  • 2 ≤ players ≤ 28
  • 1 ≤ first < second ≤ players
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEvery Way to Space the Words HardLongest Uphill Walk HardClear the Marble Row HardClearing Colored Cubes HardSix-Cell Tile Slider Hard
loading Python…
Input
players=6, first=1, second=3
Expected
[2, 3]

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