Generate Proteins from Contiguous Named Sequences
Problem statement
Each named DNA sequence occupies a half-open interval [start,end). Each protein recipe lists sequence names in order. A recipe is valid when every sequence begins exactly where the previous one ends.
Return each valid protein in recipe order as name:start:end.
For this exercise, assume a recipe is invalid and skipped when it is empty or references any unknown sequence name. A valid recipe must be nonempty, reference only known sequences, and have matching endpoints at every adjacent join.
Function
generateNamedProteins(sequenceNames: String[], ranges: int[][], recipes: String[][], proteinNames: String[]) → String[]Examples
Example 1
sequenceNames = ["AC","BC","PQ","XY","AB","BT"]ranges = [[5,15],[3,20],[15,22],[22,35],[20,32],[9,13]]recipes = [["AC","PQ"],["AC","PQ","XY"],["BC","AB"],["BT","AC"]]proteinNames = ["P1","P2","P3","P4"]return = ["P1:5:22","P2:5:35","P3:3:32"]The first three recipes are contiguous; BT ends at 13 while AC starts at 5.
Constraints
- Names are unique.
sequenceNames.length == ranges.length.recipes.length == proteinNames.length.- All interval bounds are non-negative and each start is smaller than its end.