Word Search - Leetcode 79 - Recursive Backtracking (Python)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น • 10

  • @GregHogg
    @GregHogg  5 หลายเดือนก่อน

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @nikoschaitas1378
    @nikoschaitas1378 3 หลายเดือนก่อน

    Seems like they added another test case that will prevent you from submitting successfully.
    board =
    [["a"]]
    word =
    "ab"
    In C++, you could do the following check before m==1 && n==1:
    if (word.size() > m*n)
    return false;
    At least it worked for me, with a not so pretty runtime of 576 ms.
    Again, thanks Greg! Probably wouldn't have understood the problem without this video!

  • @nikhilsastry6631
    @nikhilsastry6631 8 หลายเดือนก่อน +5

    Hey greg ... Can you make a video or make a pdf of something that consists all strings based ir other all category algorithms ... I want particularly for string like kmp ..m can you put all the algos at one place from easy to hard

    • @GregHogg
      @GregHogg  8 หลายเดือนก่อน +3

      This question is part of a playlist that has all the leetcode questions I've done on there so far. I also have them in mini playlists organized by category. I hope this helps!!

  • @MaHyxa
    @MaHyxa 3 หลายเดือนก่อน +1

    Hey Greg, thanks for the lesson. Just want to let you know that on your GitHub java solution you dont need this statement:
    if (m == 1 && n == 1) {
    return board[0][0] == word.charAt(0);
    }
    because it's failing test with a single letter in a board and always returning true without checking size of the word.
    And also you've declared a variable W, but never used it in code.

  • @dominikschweigl574
    @dominikschweigl574 7 หลายเดือนก่อน +2

    Doesnt that mean your solution doesnt work whenever the word is taking up the whole grid? Like in the example for 1x1 there is nowhere to go to and it would return false, right?

    • @GregHogg
      @GregHogg  7 หลายเดือนก่อน +2

      Actually, no, this is not the case. It's particularly when there's exactly one spot. From the position on the last character, the board would just need literally any valid space to go to. Even if that space was marked as a hashtag or a character or whatever, it just needs an actual valid (i,j) position to move to

  • @polidon1577
    @polidon1577 2 หลายเดือนก่อน

    would it be possible to store dead end sequences with the positions so that if you have a second attempt reach there in the same way, it would cancel early instead of tracing the whole word? I think that would help reduce the time complexity but I'm not sure how much that would impact the space complexity if it's even viable to do so

  • @thatnolan
    @thatnolan 6 หลายเดือนก่อน

    Any reason to use pos in backtrack() instead of i, j? You change it back to i, j in the first time anyways. The efficiency goes up quite a bit when changing pos to i, j

  • @tauicsicsics
    @tauicsicsics 12 วันที่ผ่านมา

    Great video but it would be nice if you can use more clear names (instead of "m,n,W"), the interviewers appreciate that. The one-letter variables make sense only for competitive programming. Thanks