What if we can traverse the whole row and then come to a cell in spiral manner example,
For (1,1) it went (0,1)->(0,2)->(1,2)->(1,1)
If this traversal is possible and optimal for ans what can be the approach
2d grid dp question
Yeah in that case you would be told that you can travel in more directions.
Generally in these kind of problems
dp[i][j] = minimum of all possible cells you could enter it from.
So just add the cells, but it’s usually not given like this and we are given just 2 directions so as to avoid cycles. So the approach explained works in most questions.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.