🔥🔥 Accepted || ✅✅ C++ Solution with complete explanation using map. || 100% successful 🔥🔥
Approach\n Describe your approach to solving the problem. \nFirst, we store all the elements of mat in map with its elements as key and their indexes as value. 
# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, we store all the elements of $$mat$$ in $$map$$ with its elements as key and their indexes as value. (We are storing to reduce the search complexity in matrix).\n\nWe create two more vector to store the count of the elements painted in the particular column and row. We named the vector as $$rowCount$$ and $$colCount$$.\n\nNow, we traversal through the $$arr$$ and check the row and column of that element in $$mat$$ using the $$map$$ we created.\n\nNow, further we increment the colCount for columnIndex and rowCount for the rowIndex respectively.\n\nNext, we check if the $$colCount$$ is at its max (the max of column can be the number of the i.e $$n$$). Incase, we set the value of $$ans$$ variable as the current Index and break the loop.\nSimilarly, we check for $$rowCount$$ (for row max count will be the number of column i.e $$m$$).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nFirst, $$O(n*m)$$ for storing elements and their corresponding indexes in map. Second, $$O(n*m)$$ for traversing of arr.\nSo, overall time complexity is:\n$$O(2*n*m)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n*m)$$ for map\n$$O(n)$$ for rowCount.\n$$O(m)$$ for colCount.\nSo, overall space complexity is:\n$$O(n*m + (n+m))$$\n\n# Code\n```\nclass Solution {\npublic:\n    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {\n        int n = mat.size();\n        int m = mat[0].size();\n        map<int,pair<int,int>> mp;\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        vector<int> colCount(m,0);\n        vector<int> rowCount(n,0);\n        int ans = INT_MAX;\n        for(int i = 0; i<m*n; i++){\n            auto pr = mp[arr[i]];\n            colCount[pr.second]++;\n            rowCount[pr.first]++;\n        \n            if(colCount[pr.second] == n && ans > i){\n                ans = i;\n                break;\n            }\n            \n            if(rowCount[pr.first] == m && ans > i){\n                ans = i;\n                break;\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['Ordered Map', 'C++']