Fully Explained simple Java solution
\n# Approach\nImplement a HashMap and store row and column value for each item.\n\nNow make arrays of row and column of size column and row respectively for get
\n# Approach\nImplement a HashMap and store row and column value for each item.\n\nNow make arrays of row and column of size column and row respectively for getting the filled size of that row or that column.\n\nFor each value of arr we increase the filled size by one and check if any row or col filled size equals to col or row size respectively and store the minimum index.\n\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 {\n    public int firstCompleteIndex(int[] arr, int[][] mat) {\n        int size = arr.length;\n        int n = mat.length;\n        int m = mat[0].length;\n        //Implement a HashMap and store row and column value for each item\n        HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                map.put(mat[i][j], new ArrayList<Integer>(Arrays.asList(i,j)));\n            }\n        }\n        \n        //now make arrays of row and column of size column and row respectively for getting the filled size of that row or that column.\n        int[] row = new int[n];\n        int[] col = new int[m];\n        int rval = Integer.MAX_VALUE;\n        int cval =Integer.MAX_VALUE;\n        \n        // for each value of arr we increase the filled size by one and check if any row or col filled size equals to col or row size respectively and store the minimum index.\n        for(int i = 0;i<size;i++)\n        {\n            int val = arr[i];\n            int r=map.get(val).get(0);\n            int c=map.get(val).get(1);\n            row[r]++;\n            if(row[r]==m) rval = Math.min(rval,i);\n            col[c]++;\n            if(col[c]==n) cval = Math.min(cval,i);\n            \n        }\n        return Math.min(rval,cval);\n    }\n}\n```
['Array', 'Matrix', 'Java']