✅✅✅ Python3 || Easy & Understandable || Explained
Intuition\nYou only need to keep track of how many zeroes are there.\n\n# Approach\nFirst, map each item in mat to the row and column indicies so they can be ac
# Intuition\nYou only need to keep track of how many zeroes are there.\n\n# Approach\nFirst, map each item in `mat` to the row and column indicies so they can be accessed anywhere. Next, have a list for how many zeroes are in each row and column. Then, loop over `arr` and record the painted cells. Only the 2 recently painted cells can possibly be the last cell painted in a row or column.\n\n\n# Code\n```\nclass Solution:\n    def firstCompleteIndex(self, arr, mat):\n        rowCols = {}\n        ROWS = len(mat)\n        COLS = len(mat[0])\n        for r in range(ROWS):\n            for c in range(COLS):\n                rowCols[mat[r][c]] = [r, c] # mapping cells to their r and c\n        # variables for keeping track of painted cells in a row or column\n        rowZeroes = ROWS * [0]\n        colZeroes = COLS * [0]\n        for n in range(len(arr)):\n            num = arr[n]\n            # another 2 painted cells\n            rowZeroes[rowCols[num][0]] += 1\n            colZeroes[rowCols[num][1]] += 1\n\n\n            if colZeroes[rowCols[num][1]] == ROWS: return n\n            elif rowZeroes[rowCols[num][0]] == COLS: return n            \n```\nWhy did I compare the colZeroes item with ROWS and rowZeroes with COLS?\nNotice that the length of C1 (items are wrapped in ()) is \n                how many rows there are and the length of R1(in {}) is how \n                many columns there are.\n```\n       C1     C2   C3\nR1 [ ({N}) | {N} | {N} ]\nR2 [  (N)  |  N  |  N  ]\nR3 [  (N)  |  N  |  N  ]\nR4 [  (N)  |  N  |  N  ]\n```
['Python3']