Simple Java Solution - Using Brute Force (Beats 80.60%)
Complexity
Time complexity:
O(m∗n), where m = mat.length & n = mat[0].length
Code
# Complexity
- Time complexity:
$$O(m * n)$$, where m = mat.length & n = mat[0].length

# Code
```java []
class Solution {
    public int firstCompleteIndex(int[] arr, int[][] mat) {
        int m = mat.length;
        int n = mat[0].length;
        int[] rows = new int[m];
        int[] cols = new int[n];
        HashMap<Integer, int[]> map = new HashMap<>();
        for(int i=0; i<m; i++) {
            for(int j=0; j<n; j++) {
                int[] rowCol = new int[2];
                rowCol[0] = i;
                rowCol[1] = j;
                map.put(mat[i][j], rowCol);
            }
            rows[i] = n;
        }
        for(int i=0; i<n; i++) {
            cols[i] = m;
        }

        for(int i=0; i<arr.length; i++) {
            int[] rowCol = map.get(arr[i]);
            rows[rowCol[0]]--;
            cols[rowCol[1]]--;
            if(rows[rowCol[0]] == 0 || cols[rowCol[1]] == 0) {
                return i;
            }
        }

        return arr.length-1;
    }
}
```
['Java']