Backtracking goes over the first character
BobbyL2k opened this issue · comments
Anuruth Lertpiya commented
Your code breaks when computing the distance for the input "01"
and "10"
This is because the backtrackSequence goes backward by comparing StringA[i-1] == StringB[j-1]
without a boundary check.
The fix is bellow
if(i-1 >= 0 and j-1 >= 0 and StringA[i-1] == StringB[j-1]):
paths = backtrackSequence(matrix,StringA,StringB,i-1,j-1)
return paths
Vaibhaw Raj commented
Thanks Anuruth for the correction.