CAKEDOOM: Getting Wrong answer

I have been trying to solve the problem but I am getting wrong answer and I am unable to find the flaw in my logic. Please help me correcting the solution. In my logic I first check for the validity of the string. If valid, I get the previous and next character of the current index if the length of the string is greater than or equal to three and iterate up-to all possible digits which i can put at current index and if it can’t be put i declare the string invalid. For string length two I check for next index only and try to put digit if it can be put. At last I print the string if it is valid otherwise “NO”. My solution: CodeChef: Practical coding for everyone