Тёмный
No video :(

Largest Local Values in a Matrix - Leetcode 2373 - Python 

NeetCodeIO
Подписаться 166 тыс.
Просмотров 8 тыс.
50% 1

Опубликовано:

 

14 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@freykong
@freykong 3 месяца назад
No matter it’s easy, medium or hard, just happy to see you back online. 😂
@fraserdab
@fraserdab 3 месяца назад
Trueee
@izzyko.5426
@izzyko.5426 3 месяца назад
it's crazy how you just solved it yesterday and today this same problem is on the Leetcode daily. TYSM!
@hamirmahal
@hamirmahal 3 месяца назад
The daily problem came out yesterday at 5 PM Pacific time. NeetCode usually does daily problems the day they come out.
@Sspairal
@Sspairal 3 месяца назад
Interesting to see a question trying to get us to solve what is essentially Max Pooling with a 3x3 receptive field!
@hamirmahal
@hamirmahal 3 месяца назад
How do libraries that do Max Pooling do it in practice? Do they do this brute-force approach, or is there a cleverer way?
@stitaprajnapanda4558
@stitaprajnapanda4558 3 месяца назад
@@hamirmahal using numpy can surely make things faster here?
@stitaprajnapanda4558
@stitaprajnapanda4558 3 месяца назад
This is common in Computer Vision, the output is known as Max Pooling.
@tuandino6990
@tuandino6990 Месяц назад
You can do this with 2 nested loops
@davi_singh
@davi_singh 3 месяца назад
One of the few times I got to the solution on my own and thought to myself, this is for sure gonna give a time out and was so surprised that it worked. I've for sure missed your videos over the past couple of days, thanks @neetcodeio for your videos and explanations
@hamirmahal
@hamirmahal 3 месяца назад
You can kind of tell ahead of time whether or not a solution will time out by looking at the problem constraints. For this problem, they're n == grid.length == grid[i].length 3
@davi_singh
@davi_singh 3 месяца назад
@@hamirmahal thanks man, I need to do that more often
@hamirmahal
@hamirmahal 3 месяца назад
​@@davi_singh You're welcome!
@InquisitiveLittleSteps
@InquisitiveLittleSteps 3 месяца назад
Weekly contest 3rd question please 12th May 2024 contest ...
@EranM
@EranM 3 месяца назад
Is there a better way to solve this using monotonically decreasing queue?
@qulinxao
@qulinxao 3 месяца назад
simple as: class Solution: def largestLocal(self, g: List[List[int]]) -> List[List[int]]: return[ [max(*g[i][j:j+3],*g[i+1][j:j+3],*g[i+2][j:j+3])for j in range(len(g)-2)] for i in range(len(g)-2)]
@adithyapaib
@adithyapaib 3 месяца назад
Time complexity O(N^4) ?
@akialter
@akialter 3 месяца назад
O(n^2) time O(1) space if we dont care about result matrix
@plumbumer8424
@plumbumer8424 3 месяца назад
Solve this one with only 2 nested loops for each i, j element where i is 0...N and j is 0...N-2. Firstly you need to count max of every three elements in rows and write it to the first one, after second row we count max of last three elements in each column and write it to the first one. As a result cut off last 2 rows and columns of modified grid and return it. Seems easier for me and more efficient
@ay5960
@ay5960 3 месяца назад
It is interesting that if the problem mentioned there is only one peak, it could have been solved via binary search.
@Iam_number_one
@Iam_number_one 3 месяца назад
That would have Complexity >>> O(N⁴) !!!
@sandeepsrinivas7
@sandeepsrinivas7 3 месяца назад
class Solution: def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: n = len(grid) - 2 res = [[0] * (n) for _ in range(n)] for i in range(n): for j in range(n): res[i][j] = max(max(row[j:j+3]) for row in grid[i:i+3]) return res
@tunno4586
@tunno4586 3 месяца назад
is it more effificent than my solution i think its o(n^2) ? class Solution: def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: res = [] for i in range(1, len(grid) - 1): row = [] for j in range(1, len(grid) - 1): cur_max = max(grid[i][j], grid[i+1][j], grid[i][j+1], grid[i-1][j], grid[i][j-1], grid[i+1][j+1], grid[i+1][j-1], grid[i-1][j+1], grid[i-1][j-1],) row.append(cur_max) res.append(row) return res
@chomdua1320
@chomdua1320 3 месяца назад
I did the same😂
@1TL1
@1TL1 3 месяца назад
🎉
@NeetCodeIO
@NeetCodeIO 3 месяца назад
🫡 the beginning of a year long streak of daily LCs
@juanmacias5922
@juanmacias5922 3 месяца назад
@@NeetCodeIO LFG!
@akialter
@akialter 3 месяца назад
Will this question be asked by Google 😅
@ap2s2000
@ap2s2000 3 месяца назад
sorry no
@user-jj3hc3ug6v
@user-jj3hc3ug6v 3 месяца назад
It was asked by open AI you can read about in discussion tab
@PiyushYadav-pl9jm
@PiyushYadav-pl9jm 3 месяца назад
Was the audio done by an AI trained on your voice?
@vishalthestupid
@vishalthestupid 3 месяца назад
Time Complexity - 119ms (74%) class Solution: def largestLocal(self, grid: List[List[int]]) -> List[List[int]]: n = len(grid) result = [] for i in range(n-2): a = [] for j in range(n-2): a.append(max(max(x[j:j+3]) for x in grid[i:i+3])) result.append(a) return result
Далее
Score After Flipping Matrix - Leetcode 861 - Python
22:30
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
This is Why Programming Is Hard For you
10:48
Просмотров 774 тыс.
My Brain after 569 Leetcode Problems
7:50
Просмотров 2,5 млн
So, you want to be a programmer?
20:43
Просмотров 260 тыс.
Why I Use Golang In 2024
9:21
Просмотров 287 тыс.
The Unfair Way I Got Good At LeetCode
23:02
Просмотров 73 тыс.