shlogg · Early preview
Md Ariful Haque @mah-shamim

First Completely Painted Row Or Column In Matrix

Pre-process matrix positions in O(m*n) time. Traverse arr, updating row and column frequencies. Return index where either row or column is fully painted. Time complexity: O(m*n). Space complexity: O(m*n).

2661. First Completely Painted Row or Column
Difficulty: Medium
Topics: Array, Hash Table, Matrix
You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].
Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].
Return the smallest index i at which either a row or a column will be completely painted in mat.
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...