Count of Matches in Tournament

Easy

n teams play a knockout tournament. In each round, teams are paired up; the winner of each match advances and — when the count is odd — one team gets a bye.

Return the total number of matches played until a winner is decided.

Example 1

numberOfMatches()
Input
n = 7
Output
6

Why

3 + 2 + 1 = 6 matches.

Example 2

numberOfMatches()
Input
n = 14
Output
13
Constraints
1 <= n <= 200

Topics

MathSimulation

Implement numberOfMatches in the editor and return the answer — printing it is never graded.