As Far from Land as Possible - Leetcode 1162 - Python

  Рет қаралды 9,911

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 27
@techwithkiran9956
@techwithkiran9956 Жыл бұрын
Thanks for uploading consistently the leetcode challenges, It helps us in building a habit of learning DSA every day, Keep up the good work
@sanjeevrajora7335
@sanjeevrajora7335 Жыл бұрын
nice explanation , idea of going opposite and finding maximum distance from land is really good
@AnandKumar-kz3ls
@AnandKumar-kz3ls Жыл бұрын
nice explanation as always c++ solution class Solution { public: const int x[4]={-1,1,0,0}; const int y[4]={0,0,1,-1}; int maxDistance(vector& grid) { queue q; for(int i=0;i
@narottamaswal3978
@narottamaswal3978 11 ай бұрын
thanks for c++ code can you please why this lines are used int size=q.size(); for(int s=0;s
@jeyans6759
@jeyans6759 Жыл бұрын
Thank You. Your Explanation is Great !! Please try put an explanation video on House Robber 4 as soon as possible.
@amitji9
@amitji9 Жыл бұрын
Ideally should res be res=max(res,grid[r][c]) ?
@jomarch9151
@jomarch9151 Жыл бұрын
you are not wrong (I too added this in my code), it will give the same answer. But the step is redundant since we are using bfs and it explores graph layer by layer. So the last layer of nodes visited would be the farthest water cells (as we are only updating unvisited water cells and adding it to the queue ) hence we would be storing the farthest distance.
@eliyahfarhat9918
@eliyahfarhat9918 Жыл бұрын
Very nice video.
@utkarshsinh1919
@utkarshsinh1919 Жыл бұрын
He's a genius
@Lulit999
@Lulit999 Жыл бұрын
Thank you for your solution :)
@krateskim4169
@krateskim4169 Жыл бұрын
Consistency is amazing
@dsabuddy
@dsabuddy Жыл бұрын
thanks , did the same
@nikhilgoyal007
@nikhilgoyal007 Жыл бұрын
thanks. There is no for i in range(len(q)) below the while q statement ? how will it know which level it is on without a full iteration of one of those length snapshots ?
@cosepeter2197
@cosepeter2197 Жыл бұрын
How are we checking if we have already visited same spot with water?
@hrithikkale443
@hrithikkale443 Жыл бұрын
same question
@cosepeter2197
@cosepeter2197 Жыл бұрын
@@hrithikkale443 I think I get it now. When we visit it once we increment the value by 1 hence we won't visit it the next time.
@cosepeter2197
@cosepeter2197 Жыл бұрын
@@smritiiiii yes we are adding the position in the queue but it's not preventing us from visiting the water position again. Rather, increasing the value of zero is preventing us from visiting the water position.
@smritiiiii
@smritiiiii Жыл бұрын
@@cosepeter2197 ohh yes,get it
@JohnSmith-uu5gp
@JohnSmith-uu5gp Жыл бұрын
Awesome!!!
@rick-kv1gl
@rick-kv1gl 10 ай бұрын
man how u do this salute
@cinimodmil
@cinimodmil Жыл бұрын
Thanks NC for these dailies! Also to everyone else: Hello, i just switched from Java to Python a month ago for interviews. Does anyone know when we should enqueue a tuple rather than a list or vice versa into our deque? Thank you! EDIT: Maybe I should just look up the differences between the two hmmm....
@ducthinh2412
@ducthinh2412 Жыл бұрын
If you need to modify the values then enqueue lists. If not, either is fine. The main reason (imo) you would want to use tuple is for using named tuples (look that up). If makes your code cleaner and easier to understand, especially when you store more than 2 values in your tuples
@gdbronner
@gdbronner Жыл бұрын
In Python, tuples are passed to functions as objects and they are passed by value, not by reference. When you pass a tuple to a function, a reference to the object is created, but changes to the object within the function are not reflected in the original tuple outside of the function. This is different from lists, which are mutable objects in Python and are passed by reference, meaning that any changes made to the list within a function will be reflected in the original list outside of the function
@madikhan-only
@madikhan-only Жыл бұрын
Just besttttt
@tusharbhatia5437
@tusharbhatia5437 Жыл бұрын
bro doesn't miss
Detonate the Maximum Bombs - Leetcode 2101 - Python
11:20
NeetCodeIO
Рет қаралды 14 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
Single Element in a Sorted Array - Leetcode 540 - Python
10:44
NeetCodeIO
Рет қаралды 22 М.
Construct Quad Tree - Leetcode 427 - Python
12:26
NeetCodeIO
Рет қаралды 25 М.
Shortest Path with Alternating Colors - Leetcode 1129 - Python
13:43
7 Common Excel Mistakes You HAVE to Fix Today!
11:39
MyOnlineTrainingHub
Рет қаралды 21 М.
Solving Questions With Brainpower - Leetcode 2140 - Python
14:48
Number of Enclaves - Leetcode 1020 - Python
11:39
NeetCodeIO
Рет қаралды 9 М.
Number of Closed Islands - Leetcode 1254 - Python
13:48
NeetCodeIO
Рет қаралды 16 М.
New 21 Game - Leetcode 837 - Python
19:03
NeetCodeIO
Рет қаралды 13 М.