A tournament runs as a single-elimination bracket: whoever loses is out. Each round, the remaining teams are split into pairs and every pair plays one match. If the number of teams is odd, one team gets a bye and moves on without playing.
The tournament ends when only one team is left. Given the number of teams teams, return how many matches are played in total.
Example 1
teams=6 → 5
Rounds: 6 teams play 3 matches; 3 teams play 1 match and one gets a bye; 2 teams play the final. That is 3 + 1 + 1 = 5.
Example 2
teams=9 → 8
9 teams play 4 matches (5 advance), 5 play 2 (3 advance), 3 play 1 (2 advance), then the final: 4 + 2 + 1 + 1 = 8.
Example 3
teams=1 → 0
A single team wins outright with no matches played.