Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

DP Problem with Factory Lines

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is DP Problem with Factory Lines. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output