Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
DP Problem with Factory Lines
00:00
5 left

DP Problem with Factory Lines

HardPython

Problem

A.O. Smith is scheduling sequential assembly stages for a ProLine water heater. Each stage can run on either of two factory lines, but processing times differ by line, some line-stage combinations may be unavailable, and moving between lines incurs a transfer cost.

Return the minimum total completion time and one line assignment that achieves it.

Formal Specification

Implement optimize_factory_lines(processing, transfer, start), where:

  • processing is a list of n two-element lists. processing[i][line] is the time for stage i on the specified line. A value of -1 means that assignment is unavailable.
  • transfer is a list of n - 1 2-by-2 matrices. transfer[i][previous_line][next_line] is the cost of moving from the line used for stage i to the line used for stage i + 1.
  • start is a two-element list containing the initial cost of entering each line before stage 0.

Return a dictionary with time, the minimum total time, and lines, a list of n integers containing the selected line for each stage. If no complete assignment exists, return {"time": -1, "lines": []}. Any optimal assignment is acceptable.

Constraints

  • 1 <= n <= 10^5
  • Each processing row has exactly two values
  • 0 <= processing[i][line] <= 10^6, or processing[i][line] == -1
  • 0 <= transfer[i][a][b], start[line] <= 10^6
  • transfer contains exactly n - 1 matrices

Function Signature

def optimize_factory_lines(processing, transfer, start):
Interviewer

Your question is DP Problem with Factory Lines. 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.