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.
thanks in last i did dry run understand the optimal soln after fucking 1 hr :)
😅yeah DP questions can be frustrating sometimes. glad you understand the concept.
in simple soln when u put in set its means its visited right but when u backstracking then why not removig it ?
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.
@@NO-nc7hh yeah i use java, dont know how u pass it by value, its always by referncnce
yeah i got the soln if its by value
worst, u spend aall ur engry in order to explain simple things when complex part came then blah blah blah
Which part u didn't understand?
@@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
@@sourabhgarg2890ok next time I'll try to put my point in an easier and much understandable way.
Did you understand the code?
@@NO-nc7hh i am using 3d visited[m][n][heath] its easy to understand
@@sourabhgarg2890 okay. Is that accepted because using 3d vector might cause memory out of bound.