Optimum approach to solve chewbacca and number problem

Hi, I tried to solve this question by doing something similar to the reverse a number problem. It did clear 4/5 test cases but it doesn’t work numbers like 5000 etc. I also think that this is not the optimum solution So could you please provide me with the optimum solution and reasoning behind it
regards

hi @gurkirat2600
refer this https://ide.codingblocks.com/s/643056

hi @gurkirat2600
I hope its clear or u still face any difficulty??

i still have to look at the solution will surely get back to you soon

ok @gurkirat2600 take ur time…

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.