Hints for bypassing TLE

I am struggling to solve this problem. Can anyone help me?
I tried to solve this using bfs as from CP-algorithm I found this problem under bfs category. My observation is : we can generate all the possible substrings and while generating each substring we can trace level of current and previous string. This may help us to find minimum number of steps to reach to target string. But the problem is ; there can be huge numbers of such substrings. How can I make it efficient? Or should I change the strategy? How to think over this problem or view this problem ?

LinkInversion Sort