algorithm – How to make obstacles appear randomly while leaving a way to pass for the player?

I'm trying to make a game like Crossy Road
enter the description of the image here

If you do not know what "sideline" is: In this game, you control the character (the frog in this case) to cross the streets, you must prevent your character from being hit by a car. There are also "trails". On the trails, there are trees that obstruct you and you can not cross them.

I've tried to do the game but I have a problem:
enter the description of the image here

Obstacles prevent the player to go further. What can I do to ensure that the player always has at least one way to pass?

P / s: sorry for my bad english