3286 Find a Safe Walk Through a Grid

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • In this video we will solve today's Biweekly Contest 139 second problem which is "3286. Find a Safe Walk Through a Grid".

КОМЕНТАРІ • 14

  • @sourabhgarg2890
    @sourabhgarg2890 13 днів тому +1

    thanks in last i did dry run understand the optimal soln after fucking 1 hr :)

    • @NO-nc7hh
      @NO-nc7hh  13 днів тому

      😅yeah DP questions can be frustrating sometimes. glad you understand the concept.

  • @sourabhgarg2890
    @sourabhgarg2890 13 днів тому

    in simple soln when u put in set its means its visited right but when u backstracking then why not removig it ?

    • @NO-nc7hh
      @NO-nc7hh  13 днів тому

      I have passed set by value. so while backtracking the s{row, col} is removed from set.
      If i pass it by reference than i have to keep the track of health. because there could be a possibility that if you marked some index {2, 1} in set , my health is suppose 3 and i didn't find the path. than again using some other path i reach the same index {2, 1} and my health is suppose 6 this time. Than set({2,1}) will return 0 but there could be the possibilty if finding path .
      That's why it is imp to keep the track of health . so you can track the health by using 2d matrix, using map insead of set or 3d matrix that you have done in your code.
      You can dry run testcase 3 of the question
      grid = [[1,1,1],[1,0,1],[1,1,1]]
      health = 5
      This will clear your doubt.

    • @sourabhgarg2890
      @sourabhgarg2890 13 днів тому

      @@NO-nc7hh yeah i use java, dont know how u pass it by value, its always by referncnce

    • @sourabhgarg2890
      @sourabhgarg2890 13 днів тому

      yeah i got the soln if its by value

  • @sourabhgarg2890
    @sourabhgarg2890 13 днів тому +1

    worst, u spend aall ur engry in order to explain simple things when complex part came then blah blah blah

    • @NO-nc7hh
      @NO-nc7hh  13 днів тому

      Which part u didn't understand?

    • @sourabhgarg2890
      @sourabhgarg2890 13 днів тому

      @@NO-nc7hh optmial soln , why u put dp[row][col] >= heath, u just explain it without dry run, in easy step u ddid all dry run

    • @NO-nc7hh
      @NO-nc7hh  13 днів тому

      ​@@sourabhgarg2890ok next time I'll try to put my point in an easier and much understandable way.
      Did you understand the code?

    • @sourabhgarg2890
      @sourabhgarg2890 13 днів тому

      @@NO-nc7hh i am using 3d visited[m][n][heath] its easy to understand

    • @NO-nc7hh
      @NO-nc7hh  13 днів тому

      @@sourabhgarg2890 okay. Is that accepted because using 3d vector might cause memory out of bound.