Zepruv › Coding problems

Count of Matches in Tournament

Easy · Math, Simulation

You are given an integer n, the number of teams in a tournament that has strange rules:
Return the number of matches played in the tournament until a winner is decided.

Example 1

Input: n = 7
Output: 6

Details of the tournament: - 1st Round: Teams = 7, Matches = 3, and 4 teams advance. - 2nd Round: Teams = 4, Matches = 2, and 2 teams advance. - 3rd Round: Teams = 2, Matches = 1, and 1 team is declared the winner. Total number of matches = 3 + 2 + 1 = 6.

Example 2

Input: n = 14
Output: 13

Details of the tournament: - 1st Round: Teams = 14, Matches = 7, and 7 teams advance. - 2nd Round: Teams = 7, Matches = 3, and 4 teams advance. - 3rd Round: Teams = 4, Matches = 2, and 2 teams advance. - 4th Round: Teams = 2, Matches = 1, and 1 team is declared the winner. Total number of matches = 7 + 3 + 2 + 1 = 13.

Constraints

Starter code (python)

class Solution(object):
    def numberOfMatches(self, n):
        """
        :type n: int
        :rtype: int
        """
        

Related problems

Previous: Minimum Adjacent Swaps for K Consecutive Ones · Next: Partitioning Into Minimum Number Of Deci-Binary Numbers · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.