Easy to understand solution. Beats 100% 😎😎🔥🔥
IntuitionFor every row number and column number when a value is encountered increment the count for it's row number and column number. Then check if any of them
# Intuition
For every row number and column number when a value is encountered increment the count for it's row number and column number. Then check if any of them becomes fully colored return that index as smallest value index.

# Approach
1) We need to create mapping for values till m*n so make a vector of size m*n+1 for preparing a mapping of value with it's row and col value.
2) Make 2 vectors rowColorCount and colColorCount to count how many cells of each row and each col has been colored.
3) Iterate the arr and for that value increment the count at it's row and it's col.
4) If any of them becomes full return that index of the iteration.

5) In the end if reached here returing -1 which signifies that getting that smallest index is impossible.

# Complexity
- Time complexity:
O(m*n + arr.size()) = O(m*n) 

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

# **Please like the solution if you found it useful🙏🙏🙏🙏**

![image.png](https://assets.leetcode.com/users/images/047e43ce-9a29-46bf-aef3-ce737df3b554_1737345757.6970055.png)


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

        // from map make a mapping of the value with it's {row, col}
        vector<p> mp(m*n + 1); // coz we need till index m*n

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

        vector<int> rowColorCount(m), colColorCount(n);

        for(int i = 0; i < arr.size(); i++){
            int value = arr[i];
            int row = mp[value].first, col = mp[value].second;
            
            if(++rowColorCount[row] == n || ++colColorCount[col] == m) return i;
        }

        return -1;
        
    }
};
```
['Ordered Map', 'Matrix', 'Counting', 'Iterator', 'C++']