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
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
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

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

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.