My Iterative Algo fails

I used algo in which the ans returns whenever the desired difference occurs but giving wrong ans.

Here is my code

It gives wrong answer for this test case
2
25 25251

This is because there is no way other than comparing a+b and b+a to check.
When the first 2 digits are compared you are left with deciding to choose from 251 and 25, and you choose 251, instead you need to loop again for the length of b, until you compare 1 from 251 and 2 from 25. So you need to compare a+b and b+a.

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.