Follow the movement in this video. In the first screen, the Bandit will run right up to you. As long as you trigger the star flower and run away from the Bandit, you will not get hit.
The 4th star cutscene is about 42 seconds, enough time for a quick break.
If you find yourself looking at the movement pictures very often, the practice app can help you memorize it.
(video credit: Lack)