ive been practicing on codingbat trying to figure out the problems, and things were going well until I got to the level 2 problems, now I spend a lot of time on one problem and still cant seem to figure it out. Then once I've given up on trying to solve it, and search for the solution so I can hopefully understand how the problem is solved, I don't really understand how all the code is working line by line. So here's the one I am stuck on today, hope you all can help me understand and correct where I'm wrong. (The code works, I just don't fully understand how)

https://codingbat.com/prob/p139564
Return a version of the given

string, where for every star (*) in the string the star and the chars immediately to its left and right are gone. So "ab*cd" yields "ad" and "ab**cd" also yields "ad".