Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Filter Transform and Sort Trip Data
00:00
5 left

Filter Transform and Sort Trip 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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.