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
Most Optimal Trip Planner
00:00
5 left

Most Optimal Trip Planner

HardPython

Problem

Implement public List buildMostOptimalTrip() to resolve as many customer complaints as possible: keep all orders for the same customer in a single trip (unless they can't all fit), prioritize Subscriber orders so they ship more quickly, never send orders marked fragile in the same trip as orders marked hazardous, and always move perishable goods directly to the front of the queue. Feel free to add other optimizations (e.g. multi-zone trips); document your data-structure decisions and decompose the code appropriately.

Asked in the Byteboard Code Implementation Exercise, Task 3 of the readme. Competing constraints are expected, and you are not expected to finish every possible optimization.

Function

def buildMostOptimalTrip(orders):

orders is a list of order objects, each represented as a JSON object with fields: customerId, isSubscriber, isFragile, isHazardous, isPerishable, and zone.

Return a list of orders in the chosen trip order. Preserve all valid orders, keep each customer's orders together when possible, and apply the priority rules above.

Constraints

  • 1 <= len(orders) <= 10^4
  • 0 <= customerId <= 10^9
  • isSubscriber, isFragile, isHazardous, isPerishable are booleans
  • zone is a string or null
  • Return all orders exactly once

Function Signature

def buildMostOptimalTrip(orders):
Interviewer

Your question is Most Optimal Trip Planner. 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.