C++ 🔥||Easy Solution 🎯|| Beginner Friendly⭐||Hash Table💪🏻
IntuitionThe problem involves finding the first index at which either a row or column in the matrix is completely marked. Since we need to determine the earlies


# Intuition
The problem involves finding the first index at which either a row or column in the matrix is completely marked. Since we need to determine the earliest index, it makes sense to map each matrix element to its respective row and column indices. Using this mapping, we can track the count of marked elements for each row and column as we iterate through the given array `arr`.

# Approach
1. **Mapping Elements to Indices**:
   - Create two hash maps, `row` and `col`, to store the row and column indices of each element in `mat`.

2. **Tracking Counts**:
   - Maintain two arrays, `r` and `c`, to count the number of marked elements for each row and column.

3. **Iterating Through `arr`**:
   - For each element in `arr`, update the respective row and column counts.
   - If a row or column becomes completely marked (i.e., count equals the number of elements in that row/column), return the current index.

4. **Return the Result**:
   - If no row or column is fully marked during the iteration, return the last possible index.

# Complexity
- **Time Complexity**:  
  $$O(m \times n)$$  
  - Building the `row` and `col` maps requires iterating through the entire matrix once.
  - Processing `arr` also takes $$O(m \times n)$$ since it contains all the elements of the matrix.

- **Space Complexity**:  
  $$O(m + n + m \times n)$$  
  - The `row` and `col` maps store each element of the matrix.
  - The `r` and `c` arrays require $$O(m)$$ and $$O(n)$$ space, respectively.

# Code
```cpp
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
        unordered_map<int, int> row, col;
        int m = mat.size();
        int n = mat[0].size();
        
        // Map each matrix element to its row and column indices
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                row[mat[i][j]] = i;
                col[mat[i][j]] = j;
            }
        }
        
        vector<int> r(m, 0), c(n, 0); // Count of marked elements for rows and columns
        
        // Process the elements in arr
        for (int i = 0; i < m * n; i++) {
            int num = arr[i];
            r[row[num]]++; // Increment row count
            if (r[row[num]] == n) return i; // Check if row is complete
            
            c[col[num]]++; // Increment column count
            if (c[col[num]] == m) return i; // Check if column is complete
        }
        
        return m * n - 1; // Return the last index if no row/column is fully marked
    }
};
```
['Array', 'Hash Table', 'Matrix', 'C++']