Skip to content

Commit bb98c16

Browse files
committed
Jan 20
1 parent 2a097e0 commit bb98c16

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from itertools import product
2+
from typing import List
3+
4+
5+
class Solution:
6+
def firstCompleteIndex(self, arr: List[int], mat: List[List[int]]) -> int:
7+
rows, cols = len(mat), len(mat[0])
8+
row_count, col_count = [0] * rows, [0] * cols
9+
row_map, col_map = [0] * (rows*cols+1), [0] * (rows*cols+1)
10+
11+
for row, col in product(range(rows), range(cols)):
12+
row_map[mat[row][col]] = row
13+
col_map[mat[row][col]] = col
14+
15+
for idx, num in enumerate(arr):
16+
row_count[row_map[num]] += 1
17+
if row_count[row_map[num]] == cols:
18+
return idx
19+
col_count[col_map[num]] += 1
20+
if col_count[col_map[num]] == rows:
21+
return idx
22+
23+
24+
def main():
25+
arr = [1, 3, 4, 2]
26+
mat = [[1, 4],
27+
[2, 3]]
28+
assert Solution().firstCompleteIndex(arr, mat) == 2
29+
30+
arr = [2, 8, 7, 4, 1, 3, 5, 6, 9]
31+
mat = [[3, 2, 5],
32+
[1, 4, 6],
33+
[8, 7, 9]]
34+
assert Solution().firstCompleteIndex(arr, mat) == 3
35+
36+
37+
if __name__ == '__main__':
38+
main()

2025-01-January-LeetCoding-Challenge/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
| January 15 | [2429. Minimize XOR](https://leetcode.com/problems/minimize-xor/) | Medium | Unsolved |
2121
| January 16 | [2425. Bitwise XOR of All Pairings](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | Medium | Solved |
2222
| January 17 | [2683. Neighboring Bitwise XOR](https://leetcode.com/problems/neighboring-bitwise-xor/) | Medium | Solved |
23-
| January 18 | []() | | |
24-
| January 19 | []() | | |
25-
| January 20 | []() | | |
23+
| January 18 | [1368. Minimum Cost to Make at Least One Valid Path in a Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/) | Hard | Unsolved |
24+
| January 19 | [407. Trapping Rain Water II](https://leetcode.com/problems/trapping-rain-water-ii/) | Hard | Unsolved |
25+
| January 20 | [2661. First Completely Painted Row or Column](https://leetcode.com/problems/first-completely-painted-row-or-column/) | | |
2626
| January 21 | []() | | |
2727
| January 22 | []() | | |
2828
| January 23 | []() | | |
@@ -41,4 +41,4 @@
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
4343
| Medium | 13 | 11 | 2 |
44-
| Hard | 0 | 0 | 0 |
44+
| Hard | 2 | 0 | 2 |

0 commit comments

Comments
 (0)