A tournament starts with n teams. In each round, if the number of teams is even, they pair up and n / 2 matches are played, with n / 2 winners advancing. If it is odd, one random team advances without playing, (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance. Return the total number of matches played until a winner is decided.
A tournament starts with n teams. In each round, if the number of teams is even, they pair up and n / 2 matches are played, with n / 2 winners advancing. If it is odd, one random team advances without playing, (n - 1) / 2 matches are played, and (n - 1) / 2 + 1 teams advance. Return the total number of matches played until a winner is decided.
Example 1:
Input: {"n":7}
Output: 6
Constraints:
1≤n≤200
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":7}
7 teams enter the tournament. Each match sends one team home.