Ctrl K

The Undefeated Team

Easy
A tournament has n teams numbered 0 to n - 1. For every pair of teams we know which one is stronger, recorded in an n × n matrix beats. For i ≠ j, beats[i][j] == 1 means team i is stronger than team j, and 0 means the opposite. The diagonal is all zeros. The champion is the team that no other team is stronger than. A champion is guaranteed to exist. Return its number.
Example 1
beats=[[0, 0, 0], [1, 0, 1], [1, 0, 0]] → 1

Team 1 is stronger than teams 0 and 2, and no one is stronger than team 1.

Example 2
beats=[[0, 1], [0, 0]] → 0

There are only two teams, and team 0 is stronger than team 1.

Constraints
  • 2 ≤ n ≤ 100
  • beats[i][j] is 0 or 1, and beats[i][i] == 0
  • For i ≠ j exactly one of beats[i][j] and beats[j][i] is 1
  • A champion exists
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
beats=[[0, 0, 0], [1, 0, 1], [1, 0, 0]]
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 13 tests on the server, hidden ones included.