Unique C++ easy solution without using Pairs
ApproachA map (positionMap) stores each element's position in mat for quick lookup.Two arrays, rowCount and colCount, track how many elements have been marked i
# Approach
A map (positionMap) stores each element's position in mat for quick lookup.

Two arrays, rowCount and colCount, track how many elements have been marked in each row and column.

For each element in arr, its position is determined, and the respective row and column counts are updated.

As soon as a row or column is fully marked, the current index is returned. If no row or column is completed, return -1.

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

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

# Code
```cpp []
int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
    int rows = mat.size(), cols = mat[0].size();
    
    // Map to store the position of each element in the matrix
    // Key: Matrix value, Value: Linear index (row * cols + col)
    unordered_map<int, int> positionMap;
    
    // Vectors to keep track of the count of marked elements in each row and column
    vector<int> rowCount(rows, 0), colCount(cols, 0);

    // Populate the positionMap with the position of each element in the matrix
    for (int r = 0; r < rows; ++r) {
        for (int c = 0; c < cols; ++c) {
            positionMap[mat[r][c]] = r * cols + c; // Store linear index
        }
    }

    // Iterate through the elements in the `arr` vector to simulate marking the elements
    for (int i = 0; i < arr.size(); i++) {
        int val = arr[i]; // Current value to mark

        // Retrieve the row and column of the current value using the positionMap
        int row = positionMap[val] / cols; // Extract row index from linear index
        int col = positionMap[val] % cols; // Extract column index from linear index

        // Increment the count of marked elements for the corresponding row and column
        if (++rowCount[row] == cols || ++colCount[col] == rows) {
            // If the current row or column is completely marked, return the current index
            return i;
        }
    }

    // If no row or column gets completely marked, return -1
    return -1;
}

```
['C++']