I have seen the subproblem in this ques, and I have tried many ways to optimize. But I am always getting wrong answer.
code link :https://ide.codingblocks.com/s/281866
problem link : https://leetcode.com/problems/unique-paths/
Can you help me optimize my code
hello @amitqy
yeah it has overllaping sub problem .
so u can use dynamic programming to solve it.
recurrence relation
dp[i][j]= dp[i-1][j] (coming from top)+ dp[i][j-1] (coming from left)
so just run a two loop and compute dp[i][j]
once done with iteration
return dp[n][m]
1 Like
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.