Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Trips From License Plate Logs

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Trips From License Plate Logs. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

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

Problem

LinkedIn campus parking systems record vehicle events as text logs. Given chronological logs containing license plates and event types, count how many valid parking trips were completed.

Each log line has the format "<license_plate> <event>", where <event> is either ENTRY or EXIT. A trip is counted only when a plate with an active entry later produces an EXIT. After a valid exit, that plate is no longer active and may begin another trip. Ignore unmatched exits and repeated entries while the plate is already active.

Formal Specification

Implement count_trips(logs), where logs is a list of strings ordered by event time. Return an integer equal to the number of valid entry-exit pairs. License plates contain non-whitespace characters, and event tokens use uppercase letters.

Constraints

  • 0 <= len(logs) <= 10^5
  • Each log contains exactly one plate and one event separated by whitespace
  • 1 <= len(license_plate) <= 20
  • Every event is either ENTRY or EXIT
  • Logs are ordered chronologically

Function Signature

def count_trips(logs):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output