Beats 100% , Simple JAVA Solution without Map
IntuitionIterate through matrix and keep track of maximum index in a row and a column. Return minimum of all maximum indexes.
In simple words, find maximum inde
![image.png](https://assets.leetcode.com/users/images/b1827906-a87b-4807-a2e8-e3586aaee978_1737354915.2886567.png)

# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Iterate through matrix and keep track of maximum index in a row and a column. Return minimum of all maximum indexes. 
In simple words, find maximum index (acc. to "arr" array) in all rows and columns and then return minimum among them.

# Approach
<!-- Describe your approach to solving the problem. -->

# 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) {
        int m = mat.length, n = mat[0].length;
        int[] hash = new int[m * n + 1];
        int ans = m * n;

        for (int i = 0; i < arr.length; i++)
            hash[arr[i]] = i;

        for (int i = 0; i < m; i++) {
            int index = -1;
            for (int j = 0; j < n; j++) {
                index = Math.max(index, hash[mat[i][j]]);
            }
            ans = Math.min(ans, index);
        }

        for (int i = 0; i < n; i++) {
            int index = -1;
            for (int j = 0; j < m; j++) {
                index = Math.max(index, hash[mat[j][i]]);
            }
            ans = Math.min(ans, index);
        }
        return ans;
    }
}
```
['Hash Table', 'Java']