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
Optimize Shipping Route Planning
00:00
5 left

Optimize Shipping Route Planning

MediumPython

Problem

Write a function to optimize route planning for shipping logistics at Mediterranean Shipping.

Implement optimize_route(graph, start, destination, max_stops). The directed graph maps each port to [neighbor, cost] pairs. Return {"cost": number, "path": [ports]} for the minimum-cost route using at most max_stops edges, or None when no route exists. Costs are nonnegative, and max_stops counts route edges, not intermediate ports.

Example: Port A -> Port C -> Port B -> Port D costs 2 + 1 + 2 = 5 and is preferred over more expensive alternatives.

Constraints

  • 1 <= number of ports <= 2000
  • 0 <= number of directed routes <= 10000
  • 0 <= max_stops <= 2000
  • 0 <= each route cost <= 10^6
  • Port names are nonempty strings
  • The graph may contain cycles
  • A route may not use more than max_stops edges

Function Signature

def optimize_route(graph, start, destination, max_stops):
Interviewer

Your question is Optimize Shipping Route Planning. 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.