🔥C++ ✅✅ Best Solution ( 🔥 100% faster 🔥)  0(m*n)  Easy to Understand + Comments 💯💯 ⬆⬆⬆
Complexity\n- Time complexity: O(m * n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:  O(m * n)\n Add your space complexity here, e.g. O(n)
# Complexity\n- Time complexity: $$O(m * n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:  $$O(m * n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {\n        int n = mat.size(), m = mat[0].size();\n        unordered_map<int, pair<int, int> > mp;   // this map stores  ::  value -> {row, column}\n\n        // map creation process\n        for(int i=0; i<n; i++)  {\n            for(int j=0; j<m; j++)  {\n                mp[mat[i][j]] = {i, j};\n            }\n        }\n        \n        // initialy all row and column are not visited\n        vector<int> row(n, 0);  \n        vector<int> col(m, 0);\n        \n        // traversing the array and adding one element to the corresponding row and column\n        for(int i=0; i<arr.size(); i++) {\n            pair<int, int> p = mp[arr[i]];  // we get the row and column of the cuurent element by the help of our map in O(1) time\n\n            int r = p.first, c = p.second;\n\n            row[r]++;   // adding one element in the corresponding row\n            if(row[r] >= m) return i;   // here the row is full if row contain m elements\n            \n            col[c]++;   // adding one element in the corresponding row\n            if(col[c] >= n) return i;   // here the row is full if row contain m elements\n        }\n        \n        return -1;\n    }\n};\n```
['Ordered Map', 'Matrix', 'C++']