#1688

Count of Matches in Tournament

Easy
MathSimulationMathematical InsightSimulation
LeetCode ↗

Approaches

Brute ForceOptimal
Complexity Comparison
Brute ForceOptimal Solution
Time
O(n)
O(1)
Space
O(1)
O(1)
💡

Intuition

Time O(1)Space O(1)

The optimal solution recognizes that every match eliminates one team. Thus, the total number of matches is always n - 1, where n is the initial number of teams.

⚙️

Algorithm

1 steps
  1. 1Step 1: Return n - 1 directly as the total number of matches.
solution.py2 lines
1def numberOfMatches(n):
2    return n - 1

Complexity note: The time complexity is O(1) because we are returning a single calculation without any loops or recursion.

  • 1Every match results in one team being eliminated.
  • 2The total number of matches played is always one less than the number of teams at the start.

Solutions and explanations are original Tejav content. Problem titles © LeetCode — use the LeetCode button above for the full problem statement.