Just Simulating what the questions asks to do | C++| Easy Solution
IntuitionApproach
Store the location of each number in the matrix in terms of its row index and column index (can use any data structure for this eg map, array)
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
1. Store the location of each number in the matrix in terms of its row index and column index (can use any data structure for this eg map, array)
2. Follow the directions array and increment that row and column where the num is present
3. Check if any row is full or any column is full, just return the minumum index
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(m*n) + O(m*n) => O(m*n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(m*n + 1) + O(m) + O(n) => O(m*n)

# Code
```cpp []
class Solution {
public:
    int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat) {
        int rows = mat.size();
        int col = mat[0].size();
        vector<pair<int,int>>loc(rows*col+1); //location of each number in the matrix

        //population the location of each number
        for(int i = 0; i<rows; i++){
            for(int j = 0; j<col; j++){
                int num = mat[i][j];
                loc[num] = {i,j};
            }
        }

        vector<int>r(rows, 0);//array of each row eg-> 0th row, 1st row, 2nd row etc
        vector<int>c(col, 0);//array of each column eg->0th col, 1st col, 2nd col etc
        int ans = 0;
        for(int i = 0; i<arr.size(); i++){
            int num = arr[i]; //access the number 
            int rowIndex = loc[num].first; // find its row from loc array
            int colIndex = loc[num].second;//find its col form loc arrya
            r[rowIndex]++; //increment the size of that row where this num is present
            c[colIndex]++; //similarly increment that column
            if(r[rowIndex] == col || c[colIndex] == rows){// now check if any row is full or any column is full just store that index in variable
//(row size = number of colums and column size = number of rows)
                ans = i;
                break;
            }
        }
//return ans
        return ans;
    }
};
```
['C++']