#2661

First Completely Painted Row or Column

specialist · 650 · lc medium +30 · verified · 63.9% accepted · 1,106 likes · top 67%

Description

You are given a 0-indexed integer array arr and an m x n matrix mat. Both contain every integer in [1, m * n]. Process arr in order: at step i, paint the cell of mat holding arr[i]. Return the smallest index i at which any complete row or column is painted.

Example 1:

Input: arr = [1,3,4,2], mat = [[1,4],[2,3]]
Output: 2
Explanation: The moves are shown in order, and both the first row and second column of the matrix become fully painted at arr[2].

Example 2:

Input: arr = [2,8,7,4,1,3,5,6,9], mat = [[3,2,5],[1,4,6],[8,7,9]]
Output: 3
Explanation: The second column becomes fully painted at arr[3].

Code

1
2
3