Skip to content

Commit cfdc388

Browse files
my solution for problem 1380
note: the script for creating a new note for the daily problem seems to be stuck in the queue, so i've created this one manually. i'll delete the "jeremymanning.md" note if that action ever runs!
1 parent d5067d0 commit cfdc388

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

problems/1380/jeremy.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# [Problem 1380: Lucky Numbers in a Matrix](https://leetcode.com/problems/lucky-numbers-in-a-matrix/description/)
2+
3+
## Initial thoughts (stream-of-consciousness)
4+
- Let's use set comprehensions to compute the minimum values in each row (`row_mins`) and the maximum values in each column (`column_maxes`)
5+
- Then we can just return `list(row_mins.intersect(column_maxes))`
6+
7+
## Refining the problem, round 2 thoughts
8+
- Since every element in the matrix is distinct (per the problem definition), we don't need to deal with the same value potentially appearing in different rows/columns (otherwise we'd also need to track the positions)
9+
10+
## Attempted solution(s)
11+
```python
12+
class Solution:
13+
def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:
14+
# compute the minimum for each row
15+
row_mins = {min(r) for r in matrix}
16+
17+
# compute the maximum for each column
18+
n = len(matrix[0])
19+
column_maxes = {max([r[i] for r in matrix]) for i in range(n)}
20+
21+
# return a list of the set intersection between the mins and maxes
22+
return list(row_mins.intersection(column_maxes))
23+
```
24+
- Given test cases pass
25+
- I don't think there are other special cases we need to account for that this solution won't cover; submitting...
26+
27+
![Screenshot 2024-07-18 at 8 26 55 PM](https://github.com/user-attachments/assets/e855d252-0c1d-4d8c-afba-fdcbde8e319f)
28+
29+
Solved!

0 commit comments

Comments
 (0)