Smart keypad Recursion problem

how can i approach this question, to some extent i have done my code can plzz somebody help me further.
here is the code link : https://ide.codingblocks.com/s/83641