Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Transform and Filter Data
00:00
5 left

Transform and Filter Data

EasyPython

Problem

Navan's frontend receives raw trip objects and must prepare them for an itinerary card list. Write a function that filters eligible trips, transforms each remaining object into a display-ready shape, and sorts the results by departure date.

A trip is eligible when its status is "confirmed", its totalCents is no greater than maxTotalCents, and its country appears in allowedCountries. The input order must not affect the required date ordering.

Formal Specification

Implement transform_trips(trips, maxTotalCents, allowedCountries).

  • trips is an array of objects with string fields id, travelerName, city, country, departureDate, status, and integer field totalCents.
  • maxTotalCents is a non-negative integer.
  • allowedCountries is an array of country strings.
  • Return an array of objects containing exactly id, traveler, route, totalCents, and departureDate.
  • Set traveler to travelerName and route to "city, country".
  • Sort by departureDate ascending. If dates are equal, sort by id ascending.
  • Do not mutate trips or any input object.

Constraints

  • 0 <= trips.length <= 10^5
  • 0 <= totalCents, maxTotalCents <= 10^9
  • Dates use YYYY-MM-DD format
  • Trip IDs are unique

Function Signature

def transform_trips(trips, maxTotalCents, allowedCountries):
Interviewer

Your question is Transform and Filter Data. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.