Simple by traversal || Easy Intuition || HashMap || TC: O(n* m + k)  
IntuitionIn this simply we will map the indexes so that it can be easily accessible in O(1). Once we get all the index mapped we will take a counter for each co
# Intuition
In this simply we will map the indexes so that it can be easily accessible in O(1). Once we get all the index mapped we will take a counter for each col and each row (1D array) and for each row and col we will keep track of the number of elements painted in the curr row or col at present. as soon as we get any row count == m or any col count == n then that row or col is full we can return that index.
# Approach
 
- Mapping the Numbers to Their Positions:

 - - Use a map idxs to store the position (row, column) of each number in the matrix.
This allows you to find the position of any number in O(1) time

- Maintain two arrays:
- row[n]: Tracks how many elements of each row have been encountered so far.
- col[m]: Tracks how many elements of each column have been encountered so far.
Processing Numbers in arr:

- For each number in arr:
- - Find its position (x, y) in the matrix using idxs.
Increment the count of elements seen in row[x] and col[y].
Check if row[x] equals the total number of columns 𝑚
m or col[y] equals the total number of rows 𝑛

- - If true, return the current index, because either a row or a column is completely filled.
- Return Result:

 - The first index where a row or column is completely filled is the answer.
# Complexity
- Time complexity:
O(n*m + k)
- Space complexity:
 O(n*m)
# Code
```cpp []
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
        unordered_map<int,pair<int,int>> idxs;
        int n = mat.size();
        int m = mat[0].size();
        for(int i =0 ; i<n;i++){
            for(int j = 0;j<m;j++){
                idxs[mat[i][j]] = {i,j};
            }
        }

        vector<int> row(n,0);
        vector<int> col(m,0);
        int ans;
        for(int i = 0;i<arr.size();i++){
            auto [x,y] = idxs[arr[i]];
            row[x]++;
            if(row[x] == m) {
                ans = i;
                break;
            } 
            col[y]++;
            if(col[y] == n){
                ans = i;
                break;
            }
        }
        return ans;

    }
};
```
['Hash Table', 'Matrix', 'C++']