Super Simple Solution in java/C Using Freq(track index) ( O(n*m) )
IntuitionSince we need to check for a completed row/column we can use freq/index arr to track the last used index for each individual row/col using the freq/ind
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Since we need to check for a completed row/column we can use freq/index arr to track the last used index for each individual row/col using the freq/index arr
# Approach
<!-- Describe your approach to solving the problem. -->
1. Store the idx of each elem of arr in freq array( this will help us to find the minimum idx at which we can have a completed row or column )
2. Now we check each row by row to find the minimum index of arr at which the row is completed.
3. Similar to above we check each column by column to find the minimum index of arr at which the column is completed.
4. return the smallest idx.

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

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

# Code
```java []
class Solution {
    public int firstCompleteIndex(int[] arr, int[][] mat) {
        int res = Integer.MAX_VALUE, m = mat.length, n = mat[0].length, max = 0;
        for (int a : arr)
            max = Math.max(a, max);
        int[] freq = new int[max + 1];
        for (int i = 0; i < arr.length; i++) {
            freq[arr[i]] = i;
        }
        for (int i = 0; i < m; i++) {
            int lastNumIdx = Integer.MIN_VALUE;
            for (int j = 0; j < n; j++) {
                int idx = freq[mat[i][j]];
                lastNumIdx = Math.max(lastNumIdx, idx);
            }
            res = Math.min(res, lastNumIdx);
        }
        for (int j = 0; j < n; j++) {
            int lastNumIdx = Integer.MIN_VALUE;
            for (int i = 0; i < m; i++) {
                int idx = freq[mat[i][j]];
                lastNumIdx = Math.max(lastNumIdx, idx);
            }
            res = Math.min(res, lastNumIdx);
        }
        return res;
    }
}
```
```C []
int firstCompleteIndex(int* arr, int arrSize, int** mat, int matSize,int* matColSize) {
    int m = matSize, n = matColSize[0], max = 0, res = INT_MAX;
    for (int i = 0; i < arrSize; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }
    int* freq = (int*)calloc(max + 1, sizeof(int));
    for (int i = 0; i < arrSize; i++) {
        freq[arr[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        int lastNumIdx = INT_MIN;
        for (int j = 0; j < n; j++) {
            int idx = freq[mat[i][j]];
            if (idx > lastNumIdx) {
                lastNumIdx = idx;
            }
        }
        if (lastNumIdx < res) {
            res = lastNumIdx;
        }
    }
    for (int j = 0; j < n; j++) {
        int lastNumIdx = INT_MIN;
        for (int i = 0; i < m; i++) {
            int idx = freq[mat[i][j]];
            if (idx > lastNumIdx) {
                lastNumIdx = idx;
            }
        }
        if (lastNumIdx < res) {
            res = lastNumIdx;
        }
    }
    return res;
}
```
['Hash Table', 'C', 'Java']