Count Unguarded Cells in the Grid - Leetcode 2257 - Python

  Рет қаралды 7,003

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 27
@XavierWoods-l9s
@XavierWoods-l9s 2 күн бұрын
Thanks to your leetcode daily videos and neetcode 150 list I finally got an internship opportunity at Amazon. Thanks again 🙏
@bhanunani1307
@bhanunani1307 2 күн бұрын
please give some suggestions for begineers
@XavierWoods-l9s
@XavierWoods-l9s 2 күн бұрын
@bhanunani1307 I think he already made a very good video on the same I would suggest you to follow that and keep grinding leetcode.
@debrajkundu2780
@debrajkundu2780 2 күн бұрын
He teaches DSA and take care of your eyes as well.
@safirswe
@safirswe 2 күн бұрын
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.
@fortitude242
@fortitude242 2 күн бұрын
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?
@sdemji
@sdemji Күн бұрын
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
@vignarajd1223
@vignarajd1223 2 күн бұрын
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?
@rahulsihara8946
@rahulsihara8946 2 күн бұрын
i thought you will be on break, nice to see you though.
@bhanunani1307
@bhanunani1307 2 күн бұрын
i can understand the code ver easily but i am unable to crack the problem and do it myself any help?
@jwsw
@jwsw Күн бұрын
House Robber V: Escape from jail
@Akash-rg2oe
@Akash-rg2oe 2 күн бұрын
I always wonder how this man solves these questions 2 weeks earlier before they become daily questions.
@oppie335
@oppie335 2 күн бұрын
yo !!
@luizfelipe2330
@luizfelipe2330 2 күн бұрын
I solved this problem differently. I actually used a DFS. Now, after seeing your video, I'm feeling dumb, hahaha.
@pwn2424
@pwn2424 Күн бұрын
The first solution is more efficient than the second solution right?
@floriankubiak7313
@floriankubiak7313 2 күн бұрын
It's sufficient to only mark as 0 or 1, later count the 0s.
@floriankubiak7313
@floriankubiak7313 2 күн бұрын
14:02 you can save the position of the last wall in variable => only 1 pass
@floriankubiak7313
@floriankubiak7313 2 күн бұрын
I'll dump my code here, because I prefer the way to iterate over the grids by using direction-arrays. I like the readability (I'm sure it can be better than the way I did it, advice appreciated) class Solution: def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int: grid = [[0] * n for i in range(m)] for w in walls: grid[w[0]][w[1]] = 1 for g in guards: grid[g[0]][g[1]] = 1 directions = [[-1,0],[1,0],[0,1],[0,-1]] for g in guards: for d in directions: y,x = g y += d[0] x += d[1] while 0
@ilyasramatullaev7416
@ilyasramatullaev7416 2 күн бұрын
thank you so much for making content for us
@unlucky-777
@unlucky-777 2 күн бұрын
I solved it at 650ms in first try. We take those
@rickastley4_the_second
@rickastley4_the_second 2 күн бұрын
nice video
@devmahad
@devmahad 2 күн бұрын
thanks :)
@bhanunani1307
@bhanunani1307 2 күн бұрын
please solve leetcode 493.Reverse Pairs
@EdWestfieldJr
@EdWestfieldJr Күн бұрын
`Time Limit Exceeded`
@RC23032
@RC23032 2 күн бұрын
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
@bthulasikrishna9597
@bthulasikrishna9597 2 күн бұрын
Same here 😅. We are visiting the cells which are already visited.
@RC23032
@RC23032 2 күн бұрын
@@bthulasikrishna9597 yea lol
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 147 М.
Rotating the Box - Leetcode 1861 - Python
15:14
NeetCodeIO
Рет қаралды 6 М.
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 133 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 94 МЛН
Count Unguarded Cells in the Grid | Leetcode 2257
16:19
Techdose
Рет қаралды 2,6 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 687 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 116 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 642 М.
Large Language Models explained briefly
8:48
3Blue1Brown
Рет қаралды 434 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 852 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 94 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 622 М.
docker stack is my new favorite way to deploy to a VPS
27:47
Dreams of Code
Рет қаралды 55 М.