Just Use A Simple Map
\nclass Solution {\n    public int firstCompleteIndex(int[] arr, int[][] mat) {\n        \n        int m = mat.length;\n        int n = mat[0].length;\n        
```\nclass Solution {\n    public int firstCompleteIndex(int[] arr, int[][] mat) {\n        \n        int m = mat.length;\n        int n = mat[0].length;\n        int r[] = new int[m];\n        int c[] = new int[n];\n        \n        Map<Integer, int[]> map = new HashMap<>();\n        \n        for(int i = 0; i < m; i++)\n        {\n            for(int j = 0; j < n; j++)\n            {\n                map.put(mat[i][j], new int[]{i, j});\n            }\n        }\n        \n        for(int i = 0; i < arr.length; i++)\n        {\n            int[] posi = map.get(arr[i]);\n            int x = posi[0];\n            int y = posi[1];\n            r[x]++;\n            c[y]++;\n\t\t\t// any index of r is storing painted columns of that particular row \n\t\t\t// any index of c is storing painted rows of that particular column.\n            if(r[x] == n || c[y] == m)  // as any column size of a particular row is n and any row size of a particular column is m\n                return i;\n        }\n        return arr.length - 1;\n    }\n}\n```
['Array', 'Java']