Hey there! Actually I tried to solve this problem on UVA. I submitted this solution on vjudge but it is giving TLE. On local machine it is working for all test cases that I tried. I tried to debug as well initially. Now that I am getting correct answers but TLE as well I don't know what's going wrong. Please Help.
P.S. : This is my first blog entry.
Consider this case:
You are greedily taking the first option that will let you move one square, but this means that you will get stuck on row 2, column 2. Due to the way your code is written (you will make no movement if you have no options, but won't break out of the loop either) this results in an infinite loop.
Yes! Understood. Thank you so much. I assumed that there will be always single instance of each character in 'IEHOVA' that's not the case actually.There is only one path but can have multiple occurrence of single character.
Thank you so much for your time.