Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 1.18 KB

_2661. First Completely Painted Row or Column.md

File metadata and controls

49 lines (34 loc) · 1.18 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : January 20, 2025

Last updated : January 20, 2025


Related Topics : Array, Hash Table, Matrix

Acceptance Rate : 64.3 %


Solutions

Python

class Solution:
    def firstCompleteIndex(self, arr: List[int], mat: List[List[int]]) -> int:
        rows, row_len = [0] * len(mat), len(mat[0])
        cols, col_len = [0] * len(mat[0]), len(mat)

        row_col_dict = {
            val: (i, j) 
            for i, row in enumerate(mat) 
            for j, val in enumerate(row)
        }

        for i, v in enumerate(arr) :
            r, c = row_col_dict[v]

            rows[r] += 1
            cols[c] += 1

            if rows[r] == row_len or cols[c] == col_len :
                return i

        return -1