How to avoid deadlock for Eastbound and westbound bridge scenario Java

I have the following problem. I a stuck on where and how to start and any help, direction or guidance will be much appreciated.

I need to create code where cars can cross a single lane bridge from east and west. Many cars can cross the bridge at once as long as they are headed in the same direction. But 2 cars from either side cant cross at the same time as it will cause a deadlock due to the single lane. How can I implement this.

I have looked at semaphores and concurrency in java but really need help on a starting point or an algorithm i can follow.