Count Unguarded Cells in the Grid - Leetcode 2257 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
6:50 - Coding Explanation
12:50 - Drawing Explanation
15:36 - Coding Explanation

leetcode 2257

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Thanks to your leetcode daily videos and neetcode 150 list I finally got an internship opportunity at Amazon. Thanks again 🙏

XavierWoods-ls
Автор

He teaches DSA and take care of your eyes as well.

debrajkundu
Автор

How about instead of marking a cell guarded, you mark it horizontally or vertically guarded, then when iterating through a guards position horizontally, you stop with all the previous criteria or if it's been horizontally guarded previously, then it'd mean it's guarded from another horizontal direction and we can stop. Same again vertically. I believe it'd speed things up, not enough to change the worst case time complexity, but enough.

safirswe
Автор

i thought you will be on break, nice to see you though.

ZORO__OP
Автор

Hey @Neetcode, can you group problems by the patterns you have on neetcode, you doing great but just having a playlist by pattern will help us ramp up the prep process as we will only work through patterns which we think we need to work on. What do you think?

fortitude
Автор

3:48 it can be done using binary search, the only thing is one have to invert, . "We reverse the question: iterate over all cells and for each one determine if it can be seen by some guard." Mikolaj Murasik. I agree it's annoying to code the mentioned approach but the one Mikolaj used is better tc wise, and is slightly less annoying although less straightforward than the ones from the editorial

sdemji
Автор

thank you so much for making content for us <3

ilyasramatullaev
Автор

hey, have a question!
In some of your videos, you mentioned that the time complexities shown on leetcode may not always be accurate or relevant, but here you used them to compare two approaches
this means, leetcode shows us the correct time complexity?

vignarajd
Автор

i can understand the code ver easily but i am unable to crack the problem and do it myself any help?

bhanu
Автор

I always wonder how this man solves these questions 2 weeks earlier before they become daily questions.

Akash-rgoe
Автор

It's sufficient to only mark as 0 or 1, later count the 0s.

floriankubiak
Автор

I solved it at 650ms in first try. We take those

unlucky-
Автор

The first solution is more efficient than the second solution right?

pwn
Автор

I solved this problem differently. I actually used a DFS. Now, after seeing your video, I'm feeling dumb, hahaha.

luizfelipe
Автор

please solve leetcode 493.Reverse Pairs

bhanu
Автор

l=[]
for i in range(m):
li=[]
for j in range(n):
if [i, j] in guards:
li.append('G')
continue
if [i, j] in walls:
li.append('W')
continue
li.append(0)
l.append(li)
for i, j in guards:
for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
dx, dy=i+x, j+y
while 0<=dx<m and 0<=dy<n:
if l[dx][dy]=='W':
break
l[dx][dy]='G'
dx+=x
dy+=y
uc=0
for i in range(m):
for j in range(n):
if l[i][j]==0:uc+=1
return uc

TLE and here iam

RC
visit shbcf.ru