I was asked this problem during phone screen and could come with right solution. Can someone give some insight how I should approach this?
Below is a section of a city with roads and stop lights. The letters indicate entry points where we measure traffic flow.
Each intersection has a traffic light - We want to build a program to simulate traffic flowing through the city so we can
test traffic light control algorithms with sample data.
For purposes of this exercise, your simulation should operate on 1 minute intervals,
where every minute lights (potentially) change and cars drive along roads, with each section of road taking 1 minute to drive.
J
|
A ---🚦---
|
B ---🚦---
| Example of traffic flow::
PART 1
Let's start by simulating one road - Road J.
For right now we can use a simple traffic light control: Start with both lights green on the first minute,
and then toggle back and forth between red and green each minute after that.
Your function should return the total time it took the car to travel through the city.