Ctrl K

Seeded Playoff Bracket

Medium
A playoff starts with teams teams seeded from 1 (strongest) to teams (weakest). To keep strong teams from knocking each other out early, in every round the strongest remaining slot plays the weakest one, the second strongest plays the second weakest, and so on. A slot that came out of an earlier round is as strong as the best seed in it. Write the whole bracket as one string: a match is (A,B), where A and B are team numbers or matches of the previous round written the same way, with the stronger side on the left. No spaces. For example, with 4 teams the bracket is ((1,4),(2,3)).
Example 1
teams=4 → '((1,4),(2,3))'

In round one, 1 plays 4 and 2 plays 3. The winners meet in the final.

Example 2
teams=8 → '(((1,8),(4,5)),((2,7),(3,6)))'

Round one: (1,8), (2,7), (3,6), (4,5). In round two the pairs are matched strongest against weakest again: the pair holding 1 faces the pair holding 4, and the pair holding 2 faces the pair holding 3.

Example 3
teams=2 → '(1,2)'
Constraints
  • teams = 2ˣ with 1 ≤ x ≤ 12
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Bit in the Mirror-Grown String MediumMultiplying Digit Strings MediumEvery Bracketing Result MediumNumbers That Survive a Flip MediumExpand Repeat Brackets Medium
loading Python…
Input
teams=4
Expected
'((1,4),(2,3))'

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