Unordered  Map , C++ ✅✅
Approach\n Describe your approach to solving the problem. \nThink brute force, but optimize brute force by tracking colored cells using a hash table.\n# Complex
# Approach\n<!-- Describe your approach to solving the problem. -->\nThink brute force, but optimize brute force by tracking colored cells using a hash table.\n# Complexity\n- Time complexity:O(N*M)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N*M)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n    int n,m;\n    unordered_map<int,pair<int,int>> pos;\n    unordered_map<int,int> rows,cols;\n\n    bool fillup(int x,int y)\n    {\n        rows[x]++;\n        cols[y]++;\n\n        if(rows[x]>=m || cols[y]>=n)\n        return true;\n\n        return false;\n    }\n    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {\n        n = mat.size(),m = mat[0].size();\n\n        for(int i = 0;i<n;i++)\n        {\n            for(int j = 0;j<m;j++)\n            pos[mat[i][j]] = {i,j};\n        }\n\n        for(int i = 0;i<arr.size();i++)\n        {\n            int x = pos[arr[i]].first,y = pos[arr[i]].second;\n\n            if(fillup(x,y))\n            return i;\n        }\n        return 0;\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/8592f1f7-c3a8-4941-8061-974069f1178b_1687252161.7047396.jpeg)\n
['Hash Table', 'C++']