File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2661. First Completely Painted Row or Column
3
+ * https://leetcode.com/problems/first-completely-painted-row-or-column/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat
7
+ * both contain all the integers in the range [1, m * n].
8
+ *
9
+ * Go through each index i in arr starting from index 0 and paint the cell in mat containing
10
+ * the integer arr[i].
11
+ *
12
+ * Return the smallest index i at which either a row or a column will be completely painted
13
+ * in mat.
14
+ */
15
+
16
+ /**
17
+ * @param {number[] } arr
18
+ * @param {number[][] } mat
19
+ * @return {number }
20
+ */
21
+ var firstCompleteIndex = function ( arr , mat ) {
22
+ const rows = new Array ( mat . length ) . fill ( 0 ) ;
23
+ const columns = new Array ( mat [ 0 ] . length ) . fill ( 0 ) ;
24
+ const map = new Map ( ) ;
25
+
26
+ for ( let i = 0 ; i < mat . length ; i ++ ) {
27
+ for ( let j = 0 ; j < mat [ i ] . length ; j ++ ) {
28
+ map . set ( mat [ i ] [ j ] , [ i , j ] ) ;
29
+ }
30
+ }
31
+
32
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
33
+ const [ rowIndex , columnIndex ] = map . get ( arr [ i ] ) ;
34
+ if ( ++ rows [ rowIndex ] === mat [ 0 ] . length || ++ columns [ columnIndex ] === mat . length ) {
35
+ return i ;
36
+ }
37
+ }
38
+ } ;
Original file line number Diff line number Diff line change 457
457
2649|[ Nested Array Generator] ( ./2649-nested-array-generator.js ) |Medium|
458
458
2650|[ Design Cancellable Function] ( ./2650-design-cancellable-function.js ) |Hard|
459
459
2657|[ Find the Prefix Common Array of Two Arrays] ( ./2657-find-the-prefix-common-array-of-two-arrays.js ) |Medium|
460
+ 2661|[ First Completely Painted Row or Column] ( ./2661-first-completely-painted-row-or-column.js ) |Medium|
460
461
2665|[ Counter II] ( ./2665-counter-ii.js ) |Easy|
461
462
2666|[ Allow One Function Call] ( ./2666-allow-one-function-call.js ) |Easy|
462
463
2667|[ Create Hello World Function] ( ./2667-create-hello-world-function.js ) |Easy|
You can’t perform that action at this time.
0 commit comments