Find Champion I - Problem

There are n teams numbered from 0 to n - 1 in a tournament.

Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j, team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.

Team a will be the champion of the tournament if there is no team b that is stronger than team a.

Return the team that will be the champion of the tournament.

Input & Output

Example 1 — Basic 3x3 Tournament
$ Input: grid = [[0,1,1],[0,0,1],[0,0,0]]
Output: 0
💡 Note: Team 0 beats teams 1 and 2 (grid[0][1]=1, grid[0][2]=1). Team 1 beats team 2 (grid[1][2]=1). No team beats team 0, so team 0 is the champion.
Example 2 — Different Champion
$ Input: grid = [[0,0,1],[1,0,1],[0,0,0]]
Output: 1
💡 Note: Team 1 beats teams 0 and 2. Team 0 beats team 2. No team beats team 1, so team 1 is the champion.
Example 3 — Small Tournament
$ Input: grid = [[0,1],[0,0]]
Output: 0
💡 Note: Team 0 beats team 1 (grid[0][1]=1). No team beats team 0, making team 0 the champion.

Constraints

  • n == grid.length
  • n == grid[i].length
  • 2 ≤ n ≤ 100
  • grid[i][j] is either 0 or 1
  • For all i grid[i][i] = 0

Visualization

Tap to expand
Find Champion I - Count Defeats Per Team INPUT n x n Boolean Grid j=0 j=1 j=2 i=0 0 1 1 i=1 1 0 1 i=2 0 0 0 = Team i beats j = Team i loses to j Teams 0 1 2 ALGORITHM STEPS 1 Init defeats array defeats = [0, 0, 0] 2 Count defeats If grid[i][j]=1, j loses Defeat Count Process grid[0][1]=1: Team 1 defeated grid[0][2]=1: Team 2 defeated grid[1][0]=1: Team 0 defeated grid[1][2]=1: Team 2 defeated defeats = [1, 1, 2] 3 Find zero defeats Check column sums 4 Column with all 0s = Champion (undefeated) FINAL RESULT Column Sums (Defeats) 0 Team 0 1 Team 1 2 Team 2 0 defeats 1 defeat 2 defeats CHAMPION Output: 0 Team 0 is undefeated! Key Insight: The champion is the team with ZERO defeats. In a tournament where every pair has a clear winner, count how many times each team loses (column sum). The team with 0 losses is the champion. Time: O(n^2) | Space: O(n) - Scan grid once, track defeats per team TutorialsPoint - Find Champion I | Count Defeats Per Team Approach
Asked in
Google 35 Amazon 28 Meta 22 Microsoft 18
25.4K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen