Beat 92.2% C++. O(m*n) easy solution.
IntuitionFocus on reducing time complexity by using hash arrays.ApproachStep 1 : Create a hash vector to store the row and col of the values given in the matrix
# Intuition
Focus on reducing time complexity by using hash arrays.

# Approach
**Step 1 :** Create a hash vector to store the row and col of the values given in the matrix to get row and col in O(1).

**Step 2 :** Create a rowHash and a colHash to count the number of cells painted in that particular row and col.

**Step3 :** Traverse the array---> find row, col using hash ---> increase the number of painted cells in the row and col.

**Step 4 :** Once the row or painted is painted return index (i).

# Complexity
- Time complexity:
$$O(m*n)$$

- Space complexity:
$$O(m*n) + O(m) + O(n)$$

# Code
```cpp []
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) 
    {
        int m = mat.size(), n = mat[0].size();

        vector<pair<int,int>>hash(m*n+1,{0,0});

        vector<int>rowHash(m,0) , colHash(n,0);

        for(int i=0 ; i<m ; i++)
        {
            for(int j=0 ; j<n ; j++)
            {
                int val = mat[i][j];

                hash[val]= {i,j};
            }
        }    

        for(int i=0; i<arr.size(); i++)
        {
            int val = arr[i];
            int row = hash[val].first, col = hash[val].second;

            rowHash[row]++, colHash[col]++;

            if(rowHash[row]==n || colHash[col]==m)
            {
                return i;
            }
        }
        return 0;
    }
};
```
['Hash Table', 'C++']