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
Shortest Path for Delivery Batch
00:00
5 left

Shortest Path for Delivery Batch

HardPython

Problem

A DoorDash delivery batch is represented by a weighted directed graph. Each vertex is a location, and each edge contains the travel time between two locations. Starting from a given location, find the minimum-time route that visits every required delivery location in any order.

Return the route as an ordered list of locations and its total travel time. If no route can visit all delivery locations, return ([], -1).

Formal Specification

Implement shortest_batch_route(graph, start, deliveries).

  • graph is a dictionary mapping each location to a list of [neighbor, travel_time] pairs.
  • start is a location identifier present in the graph.
  • deliveries is a list of distinct location identifiers.
  • Travel times are nonnegative integers.
  • Return [route, total_time], where route starts at start and contains every delivery location exactly at least once. Intermediate locations may repeat.

The route must be globally optimal. It is not enough to choose the nearest undelivered stop at each step.

Constraints

  • 1 <= number of locations <= 200
  • 0 <= number of directed edges <= 2,000
  • 1 <= len(deliveries) <= 12
  • Delivery location identifiers are distinct and appear in graph
  • Edge travel times are integers in the range 0 through 10^6
  • All edge weights are nonnegative

Function Signature

def shortest_batch_route(graph, start, deliveries):
Interviewer

Your question is Shortest Path for Delivery Batch. 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.