← 返回 microsoft 的题目列表DNA Sequence Concatenation
类型:online_judge
Given a list of DNA fragments, each fragment contains three elements: start_tag, end_tag, and an arbitrary string payload. start_tag and end_tag are connection strings. Requirements:
Question 1: All fragments form a continuous DNA sequence, where the start_tag of the next fragment matches the end_tag of the previous one. Output the final concatenated string.
Input: A list of tuples, such as [(XXX, ATG, "Hello"), (ATG, GCA, "World"), (GCA, TAG, "!"), (TAG, YYY, "Done")]
Output: The complete concatenated string, e.g., "HelloWorld!Done".
Question 2: Two tags can be start_tag or end_tag, and the output can be in forward or reverse order.
Output: Two possible concatenated results, e.g., "Done!WorldHello" or "HelloWorld!Done".
Question 3: The input may contain multiple DNA chains; output all possible sequences.
Please implement the code to perform these functions.
Example
Input
[("XXX", "ATG", "Hello"), ("ATG", "GCA", "World"), ("GCA", "TAG", "!"), ("TAG", "YYY", "Done")]