Hey Papa Neet, I think in the portion: for r in range(ROWS): for c in range(COLS): if grid[r][c] or not visit[r][c]: res = max(res, dfs(r, c)) return res the if statement should be an AND statement, because I'm pretty sure you're getting a little bit slower of a runtime because it'll still run the dfs if the grid is 0 due to the OR. Either way, LeetCode has to do something about time and space complexity, it can actually just lead to straight up confusion for newer people.
I think the overhead added by recursion is causing the solution to be slow. Could you please implement DFS without recursion once. That would be very helpful for me personally. Many thanks for these videos, they are very valuable to me. God bless you sir.
Hey Neet I've done your LLD course, but I still am worried on how to do well in those LLD interviews. No need for diagrams, but just coding the full OOD. Any advice? Any further practice I can do ? (big tech US) If anyone has any advice please let me know 🙏
first the function code wont execute first the visit=set() code executes and in the nested for loop we call the dfs function for the first time so we have visit in our memory so the function can access that memory since it is in the same scope
@@AbdelrahmanOmar-r3d Dude thank you so much but I'm not a beginner haha (my username is tofuegy go check it out). I also solved this problem without looking at the solution, but many people who are beginners feel discouraged to see this kind of comment you feel me?
@ it was pretty easy and it's almost a direct copy of the number of islands problem with slight change but i am not commenting on the difficulty of the problem but his ego
python is not a programming language 😅 its just simple english if you dont understand python then i would recommend you to go through neetcode python playlist it really helpful
Hey Papa Neet, I think in the portion:
for r in range(ROWS):
for c in range(COLS):
if grid[r][c] or not visit[r][c]:
res = max(res, dfs(r, c))
return res
the if statement should be an AND statement, because I'm pretty sure you're getting a little bit slower of a runtime because it'll still run the dfs if the grid is 0 due to the OR. Either way, LeetCode has to do something about time and space complexity, it can actually just lead to straight up confusion for newer people.
Good spot!
If you have an option to go between DFS and BFS, I would prefer to use BFS 100% of the time
why though
Was able to do this. confidence booster
Yes samee.
This could just be said simple Flood fill having maximum sum, did it myself but still came here☺️
Thank you for always making the daily challenge !
I like the addition of checking out the "better" answers and then showing the changes necessary to get there
Great Explanation ✨🙏🏻
I think the overhead added by recursion is causing the solution to be slow. Could you please implement DFS without recursion once. That would be very helpful for me personally. Many thanks for these videos, they are very valuable to me. God bless you sir.
If we set a cell as 0 after visiting it, we would not require an additional visit set
neat
nice, if we are allowed to change the input.
yup! I did that and the code beats 64.63% with 38ms Runtime
yes, but most of the interviewers dont prefer to change the inout provided to us.
@@shahukor4505 not just that, it also decreased the chances of passing the interview by 69%
Hey Neet I've done your LLD course, but I still am worried on how to do well in those LLD interviews. No need for diagrams, but just coding the full OOD. Any advice? Any further practice I can do ?
(big tech US)
If anyone has any advice please let me know 🙏
The description was really confusing, I didn't understand at first that we could revisit cells once fished
Is this not very similar to pacific islands?
Can anyone explain in python how set is been accessed inside function
first the function code wont execute first the visit=set() code executes and in the nested for loop we call the dfs function for the first time so we have visit in our memory so the function can access that memory since it is in the same scope
homeboys will still write in solutions "BEATS 100% 🎉🎉🎉"
Solved myself, but still came here to drop a like.
same here
Did this on my own. Let's go!
tip : don't need to add visited hash set just make grid[newX][newY] =0 and traverse for the condition grid[x][y] > 0; its more memory efficient
clist puts this question at 1413 elo => this question is at the 15th percentile of leetcode questions by difficulty
Anything below 1800 is trivial. 2000 is from where thinking starts
Straight forward problem dfs or bfs easy
ok ICPC champion
@tawfikkoptan5781 no champ
@@tawfikkoptan5781 once you know the algorithm and practice it, it'll feel like writing a loop like what neetcode said.
good luck on your journey!
@@AbdelrahmanOmar-r3d Dude thank you so much but I'm not a beginner haha (my username is tofuegy go check it out). I also solved this problem without looking at the solution, but many people who are beginners feel discouraged to see this kind of comment you feel me?
@ it was pretty easy and it's almost a direct copy of the number of islands problem with slight change but i am not commenting on the difficulty of the problem but his ego
start writing the code in java or C++ the python syntax is hard to understand for people with no experience in python.
With all due respect, you should be able to understand the syntax within a few min. If not, it's kind of a skill issue.
I agree with @Neetcode,
Also as he already explained the logic and wrote the code as well, it would be better if you make the code yourself 🙂
python is not a programming language 😅 its just simple english if you dont understand python then i would recommend you to go through neetcode python playlist it really helpful
😁 nice bait