Phone Keypad Code not Working

So, here is my code


What I wanted to know is that why I get output like
a a a b b b c c c for input: 213
I didnt get the reason why!
My observation is when i is skipped one cell for both inp[]
and out[] array for the condition when digit equals to 0 or 1

Hi @Kinjal
You are getting wrong output because in the table array second entry corresponds to “.+@$” and first entry should be " ". And also for getting all test cases pass you need to print every output string in separate line so just add endl after printing out. And you are using if(digit==0||digit==1) which is of no use as you have already considered 0 and 1 in the while loop itself, remove that also then you code will work perfectly fine.

Here is your corrected code :

If your doubt is clear then mark it as resolved.

Thanks. So now, I have changed first entry with “”.


And, it’s not showing any output for input : 203.
Why?

@Kinjal
There must be space between the ". You have written “” but it should be " ".

Yes. I have mentioned it earlier that I’m going to change the first entry. So, I just want to know the program flow.
Why it stops showing output?

I got it. So, it’s mapped with null string and that’s the reason it’s not enter into the loop so it never reach to the base case. That’s why it returns nothing.

@Kinjal
Yeah you are right.

If your doubt is clear then mark it as resolved.