Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Count of Matches in Tournament
EASY
20 mins
7 upvotes
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Count of Matches in Tournament

Contributed by
Yash_5830
Easy
yellow-spark
0/40
Avg time to solve 20 mins
Success Rate 80 %
Share
7 upvotes

Problem Statement

You are given a positive integer 'N' representing the number of teams playing in a tournament. Your task is to find the total number of matches played in the tournament if the condition for the tournament is as follows:

1. If the current number of teams(N) playing in the tournament is even then, a total of N / 2 matches will be played. The winning N / 2 teams will advance to the next round, and the losing N / 2 teams will be eliminated.

2. If the current number of teams(N) playing in the tournament is odd then, 1 team will be advanced to the next round directly, and a total of (N - 1) / 2 matches will be played. The winning (N - 1) / 2 teams will advance to the next round, and the losing (N - 1) / 2 teams will be eliminated.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
1
9
Sample Output 1:
8
Explanation for sample input 1:
In the first round, 8 teams will play 4 matches, and 1 team will be directly advanced to the next round. So including the winners of the first round, a total of 5 teams will advance to the next round.

In the second round, 5 teams will play 2 matches, and 1 team will directly advance to the next round. So including the winners of the second round, a total of 3 teams will advance to the next round.   

In the third round, 3 teams will play 1 match, and 1 team will directly advance to the next round. So including the winners of the third round, a total of 2 teams will advance to the next round.

In the final round, the 2 teams will play 1 match, and then there will be a winner of the tournament.

Therefore the total number of matches played is 4 + 2 + 1 + 1 = 8.
Sample Input 2:
2
32
78
Sample Output 2:
31
77
Reset Code
Full screen
Auto
copy-code
Console