Skip to content

2661. First Completely Painted Row or Column #1185

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We can follow these steps:

Approach

  1. Pre-process the positions of elements:

    • First, we need to store the positions of the elements in the matrix. We can create a dictionary (position_map) that maps each value in the matrix to its (row, col) position.
  2. Frequency Arrays:

    • We need two frequency arrays: one for the rows and one for the columns.
    • As we go through the arr array, we will increment the frequency of the respective row and column for each element.
  3. Check for Complete Row or Column:

    • After each increment, check if any row or column becomes completely painted (i.e., its frequency reaches the size of the matrix's columns or rows).
    • If so, return the current index.
  4. Return the result

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Jan 20, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jan 20, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants