Simple py,JAVA code exaplined in detail!! HASH+ARRAY
Problem understanding
They have given us a mtrix mat which has row rows and col columns.
They have also given us a array arr which tells us the grids which we s
# Problem understanding
- They have given us a mtrix `mat` which has `row` rows and `col` columns.
- They have also given us a array `arr` which tells us the grids which we should mark as painted in the matrix.
- we will traverse through the array from `0,1......arr.length`.when either of the *row* or *col* is completely ***painted*** we return `i`.
---

# Approach:3Hash/Hash+2Array
<!-- Describe your approach to solving the problem. -->
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- To acess the matrix position `(i,j)` while traversing array `arr` we will use a hash named `hash` which will store *mat[i][j]* as a key and *(i,j)* as value thus help in constant $O(1)$ acess.
- Then we will use `rowHash` and `colHash` to count the frequency of no of rows and columns filled.This can be a dictionary or array.
- when any `rowHash` equals to `col` and any `colHash` equals `row` we return `i`. 

# Complexity
- Time complexity:$O(n^2)$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$O(n^2)$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```Python3 []
class Solution:
    def firstCompleteIndex(self, arr: List[int], mat: List[List[int]]) -> int:
        row,col=len(mat),len(mat[0])
        hash=dict()
        #populating hash
        for i in range(row):
            for j in range(col):
                hash[mat[i][j]]=(i,j)
        rowHash={i:0 for i in range(row)}
        colHash={i:0 for i in range(col)}
        for i in range(len(arr)):
            x,y=hash[arr[i]]
            rowHash[x]+=1
            colHash[y]+=1
            if rowHash[x]==col or colHash[y]==row:
                return i
        return -1

```
```java []
class Solution {
    public int firstCompleteIndex(int[] arr, int[][] mat) {
        int row=mat.length;
        int col=mat[0].length;
        Map<Integer,int[]> hash=new HashMap<>();
        //populating hahs to access O(1)!
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                hash.put(mat[i][j],new int[]{i,j});
            }
        }
        //we can use array instead of dictionary to calculate freq!!
        int[] rowHash=new int[row];
        int[] colHash=new int[col];
        //key-logic
        for(int i=0;i<arr.length;i++){
            int[] pop=hash.get(arr[i]);
            int x=pop[0];
            int y=pop[1];
            rowHash[x]++;
            colHash[y]++;
            if(rowHash[x]==col || colHash[y]==row){
                return i;
            }
        }
        return -1;


    }
}
```
['Array', 'Hash Table', 'Matrix', 'Java', 'Python3']