Test cases failing for WordDistance2 problem

Could you help me spot the possible logic error in the code.

okay I will check for errors

Your code logic wise looks fine its probably a minor flaw in the implementation (possibly how you have updated your indexes using -1).
Still I am giving you the logic with a different implementation. give it a read

Thanks Abhinav.
But my concern was to find the that flaw only. I will look into other implementations as well.

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.