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 Жыл бұрын
nice explanation , idea of going opposite and finding maximum distance from land is really good
@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
@narottamaswal397811 ай бұрын
thanks for c++ code can you please why this lines are used int size=q.size(); for(int s=0;s
@jeyans6759 Жыл бұрын
Thank You. Your Explanation is Great !! Please try put an explanation video on House Robber 4 as soon as possible.
@amitji9 Жыл бұрын
Ideally should res be res=max(res,grid[r][c]) ?
@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 Жыл бұрын
Very nice video.
@utkarshsinh1919 Жыл бұрын
He's a genius
@Lulit999 Жыл бұрын
Thank you for your solution :)
@krateskim4169 Жыл бұрын
Consistency is amazing
@dsabuddy Жыл бұрын
thanks , did the same
@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 Жыл бұрын
How are we checking if we have already visited same spot with water?
@hrithikkale443 Жыл бұрын
same question
@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 Жыл бұрын
@@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 Жыл бұрын
@@cosepeter2197 ohh yes,get it
@JohnSmith-uu5gp Жыл бұрын
Awesome!!!
@rick-kv1gl10 ай бұрын
man how u do this salute
@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 Жыл бұрын
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 Жыл бұрын
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