Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimal Path in Metabolic Graph

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

Your question is Optimal Path in Metabolic Graph. 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

In a Genentech pathway analysis workflow, reactions form a directed metabolic pathway. Each reaction has a positive execution time and a nonnegative yield contribution. Given a maximum available time, find the feasible path from a starting metabolite to a target metabolite with the greatest total yield.

The pathway is guaranteed to be a directed acyclic graph. If multiple paths have the same maximum yield, choose the one with the smallest total time. If a tie remains, return the lexicographically smallest sequence of node IDs.

Formal Specification

Implement find_optimal_path(graph, start, target, max_time). graph is a dictionary mapping a node ID to a list of reactions. Each reaction is represented as [next_node, reaction_time, yield_value]. Return a dictionary with keys path, time, and yield. If the target cannot be reached within max_time, return {"path": [], "time": -1, "yield": 0}.

Constraints

  • 1 <= number of nodes <= 500
  • 0 <= number of reactions <= 5,000
  • 1 <= reaction_time <= max_time <= 10,000
  • 0 <= yield_value <= 10^6
  • Node IDs are unique strings
  • The graph is a directed acyclic graph

Function Signature

def find_optimal_path(graph, start, target, max_time):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output