Simulate traffic flowing through the city
Design a program to simulate traffic flow in a city. The simulation should operate in discrete 1-minute intervals. In each interval, traffic lights may change state, and cars move along road segments. Each road segment takes exactly 1 minute to traverse. The core task involves creating data models for roads, traffic lights, and cars, and implementing a function that calculates a car's total travel time through the city, including any waiting time at red lights. The traffic light control mechanism starts with both lights green and toggles their state every minute. The function should return the total travel time for a given car's journey.
AI interview prep
Core dilemma
Balancing the discrete, time-based simulation of discrete entities (cars, lights) with efficient state management and traversal logic.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Simulate traffic flowing through the city
Design a program to simulate traffic flow in a city. The simulation should operate in discrete 1-minute intervals. In each interval, traffic lights may change state, and cars move along road segments. Each road segment takes exactly 1 minute to traverse. The core task involves creating data models for roads, traffic lights, and cars, and implementing a function that calculates a car's total travel time through the city, including any waiting time at red lights. The traffic light control mechanism starts with both lights green and toggles their state every minute. The function should return the total travel time for a given car's journey.