Pls tell error in this code
@Vaibhav277
There were two errors in your code.
- You were taking the input into k at the wrong position. Take it along n and m.
- Second when (v1[i-1] != v2[j-1]) , it is not necessary to set the two positions equal and move along. A better solution might be present in case you explore the state (i + 1, j) and (i, j + 1). So if chances are greater than zero, then setting the indexes equal is one of the options. The other two are the ones mentioned above. Try implementing a top down solution and you will be able to understand it.
In case u face any issue, feel free to revert.
still test cases not passing… can u pls make changes in my code and highlight them with comments so that i can understand where i was going wrong
@Vaibhav277
Try to implement using top down approach and you will be able to understand the concept behind the point I am making.
i am tried but test cases not passing… pls suggest changes in code only
@Vaibhav277
This is a 3D dp. You are trying to solve it using only two variables but actually there is an important step, that is to take into account the number of changes left. It is thus a 3D dp solution. You thus need to work on a 3D dp solution. It is because of this that I am suggesting to work on a top down approach.
Please feel to revert if you face any difficulty.
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.