Imagine you're playing a unique painting game! You have a grid (matrix) filled with numbers from 1 to m×n, and an instruction array that tells you which numbers to paint in order.
Your task is to follow the painting instructions one by one. For each number in the instruction array, find that number in the grid and paint it. The moment you complete painting an entire row or an entire column, you win!
Goal: Find the smallest index in the instruction array at which you'll have your first complete row or column painted.
Input: An integer array arr (painting instructions) and an m×n matrix mat containing all numbers 1 to m×n exactly once.
Output: The index i where painting arr[i] completes the first full row or column.
Input & Output
Constraints
- m == mat.length
- n == mat[i].length
- arr.length == m * n
- 1 ≤ m, n ≤ 105
- 1 ≤ m * n ≤ 105
- All values in arr are distinct and in range [1, m * n]
- All values in mat are distinct and in range [1, m * n]