✅ 🌟 JAVA SOLUTION ||🔥 BEATS 100% PROOF🔥|| 💡 CONCISE CODE ✅ || 🧑‍💻 BEGINNER FRIENDLY
Complexity
Time complexity:O(m * n)

Space complexity:O(m * n)
Code
# Complexity
- Time complexity:O(*m* * *n*)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(*m* * *n*)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {

    public int firstCompleteIndex(int[] arr, int[][] mat) {
        // Map to store the index of each number in the arr
        Map<Integer, int[]> pos=new HashMap<>();
        int n=mat.length;
        int m=mat[0].length;
        for(int row=0;row<n;row++)
        {
            for(int col=0;col<m;col++)
            {
                pos.put(mat[row][col], new int[]{row, col});
            }
        }

        int[] rowCount=new int[n];
        int[] colCount=new int[m];
        for(int i=0;i<arr.length;i++)
        {
            int[] idx=pos.get(arr[i]);
            int row=idx[0];
            int col=idx[1];

            rowCount[row]++;
            colCount[col]++;
            if(rowCount[row]==m || colCount[col]==n)
            {
                return i;
            }
        }
        return -1;
    }
}
```
['Array', 'Hash Table', 'Matrix', 'Java']