Easy C++ solution✅ | Beginner friendly💯
CodeComplexity
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 m = mat.size();
        int n = mat[0].size();
        map<int, int> cnt_row, cnt_col;
        map<int, pair<int, int>> location;
        for(int i=0; i<m; i++){
            for(int j=0; j<n; j++){
                location[mat[i][j]] = {i, j};
            }
        }
        for(int i=0; i<m*n; i++){
            cnt_row[location[arr[i]].first]++;
            if(cnt_row[location[arr[i]].first] == n) return i;
            cnt_col[location[arr[i]].second]++;
            if(cnt_col[location[arr[i]].second] == m) return i;
        }
        return -1;
    }
};
```
# Complexity
- Time complexity: O(N*M)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(N*M)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
['Array', 'Hash Table', 'Matrix', 'C++']