Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Vehicle Mode Duration by Trip

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Vehicle Mode Duration by Trip. Read through the requirements and the two tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given Waymo Driver state-change logs and trip boundaries. Write a PostgreSQL query to calculate, for each trip, the total time the vehicle spent in autonomous mode versus manual mode. Treat each state row as effective until the next state change within the same trip; for the final state in a trip, use the trip end time. Ignore rows where the state is NULL.

Schema

waymo_trips
ColumnTypeDescription
trip_idPKINTUnique trip identifier
vehicle_idINTVehicle identifier
route_nameVARCHAR(100)Waymo service route or area
trip_start_tsTIMESTAMPTrip start timestamp
trip_end_tsTIMESTAMPTrip end timestamp
waymo_vehicle_state_logs
ColumnTypeDescription
log_idPKINTUnique state log identifier
trip_idINTTrip tied to the state log
event_tsTIMESTAMPTimestamp when the vehicle state changed
vehicle_stateVARCHAR(20)Vehicle mode such as autonomous or manual
Tableswaymo_tripswaymo_vehicle_state_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results