Easy solution
IntuitionThe problem requires determining the first index in the array arr at which either a row or a column in the matrix mat is completely filled. The key obs
# Intuition
The problem requires determining the first index in the array arr at which either a row or a column in the matrix mat is completely filled. The key observation is that we can track the fill count of rows and columns as we iterate through arr and check if any row or column reaches its full size.



# Approach
Mapping Matrix Values to Indices:

Use a HashMap to store the row and column indices for each value in the matrix mat. This enables quick lookups of the position of any number in mat.
Tracking Row and Column Counts:

Use two arrays:
rows[] to store the count of filled cells for each row.
cols[] to store the count of filled cells for each column.
Iterate Through the Array arr:

For each element in arr, get its position (row and column) from the HashMap.
Increment the corresponding row and column counters.
Check if the row or column is completely filled (i.e., the count equals the number of columns or rows, respectively).
If a row or column is fully filled, return the current index of arr.
Return Default Value:

If no row or column is completely filled by the end of the iteration, return 0 as specified in the code.

# Complexity
- Time complexity:
Precomputing Matrix Indices: O(n×m), where n is the number of rows and m is the number of columns in the matrix.
Processing Array arr: O(k), where k is the length of arr.
Overall Complexity: O(n×m+k).

- Space complexity:
  HashMap to store matrix positions: O(n×m).
Arrays rows[] and cols[]: O(n+m).
Overall Complexity: O(n×m).

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

        }
        for(int i=0;i<arr.length;i++){
            int ind1=hm.get(arr[i]).get(0);
            int ind2=hm.get(arr[i]).get(1);
            rows[ind1]++;
            cols[ind2]++;
            if(rows[ind1]>=m)
            return i;
           if(cols[ind2]>=n)
           return i;
        }
        return 0;
    }
}
```
['Array', 'Hash Table', 'Matrix', 'Java']