Skip to main content
Back to problems
#1688
Easy Algorithms

Count of matches in tournament

Math Simulation
86.3% acceptance
Feb 25, 2026
1874
246
You are given an integer n, the number of teams in a tournament. If teams are even: n/2 matches, n/2 advance. If teams are odd: (n-1)/2 matches, (n+1)/2 advance. Return the number of matches played until a winner is decided.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn number_of_matches(n: i32) -> i32 {
    // Each match eliminates exactly 1 team. To get from n teams to 1 winner: n-1 matches.
    n - 1
  }
}