FunctionRacerProblemsRace

Matches in a Tournament

BeginnerMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems