Count of Matches in Tournament

Easy Topics Company Tags

A tournament starts with n teams. In each round, teams play in pairs and only the winners advance. If the number of teams is odd, one team advances without playing; the remaining teams are paired normally. Return the total number of matches played until one champion remains.

Example 1:

Input: n = 1

Output: 0

Explanation: The sole team is already the champion, so no match is played.

Example 2:

Input: n = 4

Output: 3

Explanation: The first round has two matches and the final has one, for a total of three.

Example 3:

Input: n = 5

Output: 4

Explanation: Two matches in the first round leave three teams. One match in the next round leaves two teams, and the final decides the champion. The total is 2 + 1 + 1 = 4.

Constraints:

  • 1 <= n <= 200


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.