First, have a Fire Flower equipped and a Mini Mushroom stored. In World 4 Haunted House, go to the pipe with two red blocks beside it and press the red button while avoiding the Balloon Boo. Get on top of the pipe, turn mini, then wall jump on the pipe to reach a ledge. Wall jump up the tiny passage above the ledge without taking the door yet. Keep wall jumping to get the third coin, then take the door. Quickly run to the flag very because a Boo might be there. Save the game once you're in World 7.