EasyNo. 2923

Find Champion I — LeetCode 2923 Python Solution

Topics
Array, Matrix
Reading time
2 min

The 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.

Example

Input
grid = [[0,1],[0,0]]
Output
0
Explanation
There are two teams in this tournament.

Python solution

PythonSolution
class Solution:
    def findChampion(self, grid: List[List[int]]) -> int:
        for i, row in enumerate(grid):
            if all(x == 1 for j, x in enumerate(row) if i != j):
                return i

Complexity

Time
O(n2)where n is the number of teams
Space · auxiliary
O(1)

Pattern: Matrix and Grid

Treat a 2-D grid as a graph whose neighbours are the four adjacent cells. LeetCode 2923. Find Champion I is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Matrix.

The matrix and grid guide has the Python template for the pattern and the 216 LeetCode problems that use it.

Related problems

Related problems
No.ProblemDifficulty
0054Spiral MatrixMedium
0059Spiral Matrix IIMedium
0289Game of LifeMedium
0498Diagonal TraverseMedium
0566Reshape the MatrixEasy
0661Image SmootherEasy

Frequently asked questions

How hard is LeetCode 2923. Find Champion I?

LeetCode 2923. Find Champion I is rated Easy on LeetCode.

What is the time complexity of LeetCode 2923. Find Champion I?

The Python solution on this page runs in O(n2), where n is the number of teams.

What is the space complexity of LeetCode 2923. Find Champion I?

The Python solution on this page uses O(1) auxiliary space.

What topics does LeetCode 2923. Find Champion I cover?

LeetCode 2923. Find Champion I is tagged Array and Matrix on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.