True, if you print out pred[-1] after the first and the second loop, you will see that somewhere pred[-1] got overwritten in the second for loop.
I had the same problem. Everything I implemented was correct.
I observed that the pred[-1] was correctly assigned (with “–s–”) in the first loop. But, after the second loop pred[-1] is “#”. I could not find how pred[-1] got overwritten.
This is the problem you also faced.
How I solved it:
store pred[m - 1] in some variable (say temp) and then before returning replace pred[-1] with temp.
It worked.
Hi @Mubsi
I have the same issue, I tried changing the range of the second for loop but in both cases, I got the same error for the mismatch of the last character in a particular test case.
Hello sir @Mubsi, I am getting same error with my work, I am getting ‘#’ instead of ‘–s–’ . Can you please help me fix it? My lab id is: izslfbkjahyx. Thank you!
Hey @NIKHILM710,
Welcome to the community. As you can see it’s a long thread and many common mistakes have already been discussed regarding the implementation of this function. So, can you please go through them once, and see if either of these help.
Hi Elemento,
I visited the thread yesterday. But it didn’t helped me to find out error in Viterbi backward function. {Moderator’s Edit: Please don’t mention Lab ID unless explicitly asked for}
Hey @NIKHILM710,
The mentors don’t have the access to your labs, only Mubsi has that. Can you please DM me the implementation of your viterbi_backward function?