Maximum Number of Fish in a Grid - Leetcode 2658 - Python

Поділитися
Вставка
  • Опубліковано 7 лют 2025

КОМЕНТАРІ • 44

  • @jayjw1
    @jayjw1 10 днів тому +5

    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.

  • @unlucky-777
    @unlucky-777 10 днів тому +7

    If you have an option to go between DFS and BFS, I would prefer to use BFS 100% of the time

  • @RubenGarciaCS
    @RubenGarciaCS 11 днів тому +6

    Was able to do this. confidence booster

  • @maanas_sehgal
    @maanas_sehgal 11 днів тому +3

    This could just be said simple Flood fill having maximum sum, did it myself but still came here☺️

  • @business_central
    @business_central 10 днів тому

    Thank you for always making the daily challenge !

  • @armantavakoli5314
    @armantavakoli5314 11 днів тому +2

    I like the addition of checking out the "better" answers and then showing the changes necessary to get there

  • @atharvakalbande940
    @atharvakalbande940 11 днів тому

    Great Explanation ✨🙏🏻

  • @SAYEEDURRAHMAN-nn9qo
    @SAYEEDURRAHMAN-nn9qo 10 днів тому

    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.

  • @yang5843
    @yang5843 11 днів тому +19

    If we set a cell as 0 after visiting it, we would not require an additional visit set

    • @spitfire7019
      @spitfire7019 11 днів тому

      neat

    • @Aaron-cp9tt
      @Aaron-cp9tt 11 днів тому

      nice, if we are allowed to change the input.

    • @shahukor4505
      @shahukor4505 11 днів тому +1

      yup! I did that and the code beats 64.63% with 38ms Runtime

    • @whatthefucksuresh
      @whatthefucksuresh 11 днів тому

      yes, but most of the interviewers dont prefer to change the inout provided to us.

    • @daniyalhodekar5680
      @daniyalhodekar5680 10 днів тому

      ​@@shahukor4505 not just that, it also decreased the chances of passing the interview by 69%

  • @business_central
    @business_central 10 днів тому +1

    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 🙏

  • @jeehar1
    @jeehar1 11 днів тому

    The description was really confusing, I didn't understand at first that we could revisit cells once fished

  • @alessandrog498
    @alessandrog498 10 днів тому

    Is this not very similar to pacific islands?

  • @vikneshcs
    @vikneshcs 11 днів тому

    Can anyone explain in python how set is been accessed inside function

    • @whatthefucksuresh
      @whatthefucksuresh 11 днів тому

      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

  • @user-my6yf1st8z
    @user-my6yf1st8z 10 днів тому

    homeboys will still write in solutions "BEATS 100% 🎉🎉🎉"

  • @justelis4078
    @justelis4078 11 днів тому

    Solved myself, but still came here to drop a like.

  • @yhbarve
    @yhbarve 11 днів тому +1

    Did this on my own. Let's go!

  • @WebSleek
    @WebSleek 11 днів тому +1

    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

  • @krityaan
    @krityaan 10 днів тому

    clist puts this question at 1413 elo => this question is at the 15th percentile of leetcode questions by difficulty

    • @zanies6288
      @zanies6288 10 днів тому

      Anything below 1800 is trivial. 2000 is from where thinking starts

  • @staywithmeforever
    @staywithmeforever 11 днів тому +4

    Straight forward problem dfs or bfs easy

    • @tawfikkoptan5781
      @tawfikkoptan5781 10 днів тому +1

      ok ICPC champion

    • @staywithmeforever
      @staywithmeforever 10 днів тому

      @tawfikkoptan5781 no champ

    • @AbdelrahmanOmar-r3d
      @AbdelrahmanOmar-r3d 10 днів тому

      ​@@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!

    • @tawfikkoptan5781
      @tawfikkoptan5781 10 днів тому

      @@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?

    • @tawfikkoptan5781
      @tawfikkoptan5781 10 днів тому +2

      @ 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

  • @dakshchandore6435
    @dakshchandore6435 11 днів тому

    start writing the code in java or C++ the python syntax is hard to understand for people with no experience in python.

    • @NeetCodeIO
      @NeetCodeIO  11 днів тому +4

      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.

    • @maanas_sehgal
      @maanas_sehgal 11 днів тому

      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 🙂

    • @whatthefucksuresh
      @whatthefucksuresh 11 днів тому

      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

    • @user-my6yf1st8z
      @user-my6yf1st8z 10 днів тому

      😁 nice bait