Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flight Logs Aggregation

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

Your question is Flight Logs Aggregation. 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

BCG X's flight-planning analytics pipeline receives flight logs from multiple routes. Implement a function that calculates the average duration, average ticket price, and total number of flights for an exact departure and destination pair.

Formal Specification

The function receives logs, a list of dictionaries, plus departure and destination strings. Each log contains:

  • departure: airport code string
  • destination: airport code string
  • duration_minutes: positive integer
  • ticket_price: non-negative number

Return a dictionary with keys average_duration, average_ticket_price, and total_flights. Average values must be floating-point numbers. If no flight matches the route, return both averages as 0.0 and total_flights as 0.

Matching is case-sensitive, and only exact departure and destination matches count. Do not modify the input list.

Constraints

  • 0 <= len(logs) <= 10^5
  • Airport codes contain 3 uppercase English letters
  • 1 <= duration_minutes <= 2,000
  • 0 <= ticket_price <= 100,000
  • Every log contains departure, destination, duration_minutes, and ticket_price

Function Signature

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