Matches in a Tournament
A knockout tournament starts with teams teams. In each round, teams are paired up and each pair plays one match; the loser is out. If the number of teams is odd, one team gets a free pass to the next round. Rounds continue until one team remains. Return the total number of matches played.
Example 1
teams 7
returns 6
3 + 2 + 1 = 6 matches.
Constraints
1 <= teams <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Number of Common FactorsBeginner
- Power of FourBeginner
- Power of ThreeBeginner
- Power of TwoBeginner
- Product Minus Sum of DigitsBeginner
- Seconds to ClockBeginner
- Staircase of StonesBeginner
- Steps to Reduce to ZeroBeginner