Simple Logic ... Easy Approach ... Happy Coding🌞
Intuitionstore the indexes of elements of matrix in an unordered_mapApproach1.Iterate through the array and push the row and column from the map into the row an
# Intuition
store the indexes of elements of matrix in an unordered_map

# Approach
1.Iterate through the array and push the row and column from the map into the row and column vector.
2.check that if the size of the vector becomes equal to total number of rows or columns . return the i at that point

# Complexity
- Time complexity:
O(N*M)

- Space complexity:
O(N*M)

# Code
```cpp []
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
        int n=mat.size();
        int m=mat[0].size();
        unordered_map<int,pair<int,int>> mp;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                mp[mat[i][j]]={i,j};
            }
        }
        vector<vector<int>> row(n);
        vector<vector<int>> col(m);
        for(int i=0;i<arr.size();i++){
            pair<int,int> p=mp[arr[i]];
            row[p.first].push_back(1);
            col[p.second].push_back(1);
            if(row[p.first].size()==m){
                return i;
            }
            if(col[p.second].size()==n){
                return i;
            }
        }
        return 1;
    }
};
```
['Array', 'Hash Table', 'Matrix', 'C++']