"Simple" ahh Solution | Beats 100%.
IntuitionApproach
Create a hashmap to store the positions of elements in the matrix.
Traverse the matrix and map each element to its row and column indices.
Ini
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1. Create a hashmap to store the positions of elements in the matrix.
2. Traverse the matrix and map each element to its row and column indices.
3. Initialize arrays to track painted counts for rows and columns.
4. Iterate through the array arr to simulate painting:
    - Get the position of the current element from the hashmap.
    - Increment the painted count for the corresponding row and column.
    - Check if the row or column is completely painted.
    - Return the current index if a row or column is fully painted.
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```java []
class Solution {
    public int firstCompleteIndex(int[] arr, int[][] mat) {
        HashMap<Integer, int[]>map = new HashMap<>();
        int rowcount = mat.length;
        int colcount = mat[0].length;
        for(int i=0;i<rowcount;++i){
            for(int j=0;j<colcount;++j){
                map.put(mat[i][j] , new int[]{i,j});
            }
        }
        int rowpaint[] = new int[rowcount];
        int colpaint[] = new int[colcount];

        for(int i=0;i<arr.length;++i){
            int pos[] = map.get(arr[i]);
            rowpaint[pos[0]]++;
            colpaint[pos[1]]++;
            if(rowpaint[pos[0]]==colcount || colpaint[pos[1]]==rowcount){
                return i;
            }
        }
        return 0;
    }
}
```
['Java']