As Far from Land as Possible - Leetcode 1162 - Python

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

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 28
@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
@jeyans6759
@jeyans6759 Жыл бұрын
Thank You. Your Explanation is Great !! Please try put an explanation video on House Robber 4 as soon as possible.
@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
@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.
@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 ?
@Lulit999
@Lulit999 Жыл бұрын
Thank you for your solution :)
@utkarshsinh1919
@utkarshsinh1919 Жыл бұрын
He's a genius
@krateskim4169
@krateskim4169 Жыл бұрын
Consistency is amazing
@chandravijaya1410
@chandravijaya1410 Жыл бұрын
Thank you
@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
@dsabuddy
@dsabuddy Жыл бұрын
thanks , did the same
@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
@rick-kv1gl
@rick-kv1gl 10 ай бұрын
man how u do this salute
@JohnSmith-uu5gp
@JohnSmith-uu5gp Жыл бұрын
Awesome!!!
@madikhan-only
@madikhan-only Жыл бұрын
Just besttttt
@tusharbhatia5437
@tusharbhatia5437 Жыл бұрын
bro doesn't miss
Shortest Path with Alternating Colors - Leetcode 1129 - Python
13:43
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 211 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН
ATUALIZAÇÕES SOBRE O EDGYVERSE - Aftermath in Behavior
13:09
Number of Enclaves - Leetcode 1020 - Python
11:39
NeetCodeIO
Рет қаралды 9 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 852 М.
1162. As Far from Land as Possible | LeetCode Medium
22:54
DeepCodes
Рет қаралды 1,1 М.
Maximum Matrix Sum - Leetcode 1975 - Python
16:07
NeetCodeIO
Рет қаралды 1,1 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 329 М.
Detonate the Maximum Bombs - Leetcode 2101 - Python
11:20
NeetCodeIO
Рет қаралды 14 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 116 М.
Matchsticks to Square - Leetcode 473 - Python
15:48
NeetCode
Рет қаралды 28 М.
Number of Closed Islands - Leetcode 1254 - Python
13:48
NeetCodeIO
Рет қаралды 16 М.
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 211 МЛН