Leetcode string doubt

I am unable to solve can u share the code and explain the it

This problem is same as smart keypad might be explained in your course. You can search it in your course content. If not found let me know.

I cannot find it.Please help me to solve it.

Do it somewhat like this


Source code

Explanation video https://youtu.be/IN3uTs8afz4

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.