🚀 "Crack the Code: First Completely Painted Row or Column!" 🚀
אִינטוּאִיצִיָהכאשר פותרים בעיה זו, הרעיון המרכזי הוא לעקוב אחר התקדמות הצביעה של כל שורה ועמודה בזמן אמת. על ידי שמירה על מונים, נוכל לקבוע ביעילות מתי שורה או

# Intuition  
When solving this problem, the key idea is to track the painting progress of each row and column in real time. By maintaining counters, we can efficiently determine when a row or column is fully painted.

# Approach  
1. **Mapping Numbers to Positions**:  
   - First, map each number in the matrix to its position (row, column). This allows quick lookups for any number in the array.  
2. **Tracking Progress**:  
   - Use two counters: one for rows and one for columns. Increment the corresponding counter whenever a number is "painted."  
3. **Checking Completion**:  
   - After updating the counters, check if the current row or column has been fully painted. If yes, return the index of the current number from the array.  
4. **Edge Case**:  
   - If no row or column is completely painted (highly unlikely due to constraints), return `-1`.

# Complexity  
- **Time Complexity**:  
  $$O(m \times n + k)$$, where \(m\) and \(n\) are the dimensions of the matrix, and \(k\) is the length of the array.  
  - \(O(m \times n)\) for mapping matrix numbers to positions.  
  - \(O(k)\) for processing the array.  

- **Space Complexity**:  
  $$O(m + n)$$, for the row and column counters.  

# Code  
```python
class Solution(object):
    def firstCompleteIndex(self, arr, mat):
        """
        :type arr: List[int]
        :type mat: List[List[int]]
        :rtype: int
        """
        num_to_pos = {}
        for i in range(len(mat)):
            for j in range(len(mat[0])):
                num_to_pos[mat[i][j]] = (i, j)
        
        row_count = [0] * len(mat)
        col_count = [0] * len(mat[0])
        
        for index, num in enumerate(arr):
            row, col = num_to_pos[num]
            
            row_count[row] += 1
            col_count[col] += 1
            
            if row_count[row] == len(mat[0]) or col_count[col] == len(mat):
                return index
        
        return -1
```

# 🔥 Why This Stands Out  
- **Efficiency**: Combines preprocessing and real-time checks for optimal performance.  
- **Simplicity**: Clear logic with minimal data structures.  
- **Scalability**: Handles larger matrices and arrays effortlessly.  


['Python']