TLE error in smart Keypad - I

TLE error in the problem.
I hv done it iteratively works fine for the sample test case.
plz check the code.

problem :
https://online.codingblocks.com/app/player/39658/content/37364/4740/code-challenge

code : https://ide.codingblocks.com/s/178427

Hi @sengarankit98
In your code you have assumed that input string will be of length two only but this is not true as length of input string can be <=10. Try to use recursion to solve this problem. Give it a try and if still you are unable to code then have a look at code below and try to dry run it and understand the logic behind it.

Here is the solution for this problem :

If your doubt is clear then mark it as resolved.