Assemble DNA payload strings from tagged fragments
Problem: Assemble DNA Payload Strings from Tagged Fragments
You are provided with a list of DNA-like fragments. Each fragment is represented as a tuple containing:
start_tag: A stringend_tag: A stringpayload: A string
A valid DNA chain is constructed by ordering these fragments such that the end_tag of one fragment precisely matches the start_tag of the subsequent fragment. The final assembled DNA string is formed by concatenating the payloads of the fragments in their chain order.
Assume that tags are arbitrary strings (e.g., "AAA", "AAC").
Part 1: Single Forward Chain
Given a set of fragments that are guaranteed to form exactly one continuous chain following the rule prev.end_tag == next.start_tag, your task is to assemble and output the final concatenated string.
Example:
Input:
(XXX, ATG, "Hello")(ATG, GCA, "World")(GCA, TAG, "!")(TAG, YYY, "Done")
Output:
"HelloWorld!Done"
Part 2: Chain Traversal in Either Direction
Now, consider each fragment as a bidirectional connection between its start_tag and end_tag. You may traverse the final chain in either the forward or the reverse direction.
- Forward traversal: Outputs payloads in their original forward order.
- Reverse traversal: Outputs payloads in their reverse order (i.e., the last fragment's payload first, then the second to last, and so on).
Either the forward or reverse assembled string is considered an acceptable output.
For the example above, valid outputs include:
"HelloWorld!Done"(forward)"Done!WorldHello"(reverse)
Part 3: Multiple DNA Chains
In this final part, the input fragments may form multiple disjoint chains. It is still assumed that these can be arranged into simple chains without any branching within a single chain.
Your task is to output all assembled strings, one for each distinct chain. The order of these output strings does not matter.
Output Format
- For Part 1 and Part 2: A single string.
- For Part 3: A list or array of strings (one for each chain).
AI interview prep
Core dilemma
The central engineering conflict is efficiently reconstructing linear sequences (chains) from an unordered set of fragments, managing different traversal directions, and identifying all distinct components in a graph-like structure, all while optimizing for string concatenation performance and handling potential scale.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Assemble DNA payload strings from tagged fragments
Problem: Assemble DNA Payload Strings from Tagged Fragments
You are provided with a list of DNA-like fragments. Each fragment is represented as a tuple containing:
start_tag: A stringend_tag: A stringpayload: A string
A valid DNA chain is constructed by ordering these fragments such that the end_tag of one fragment precisely matches the start_tag of the subsequent fragment. The final assembled DNA string is formed by concatenating the payloads of the fragments in their chain order.
Assume that tags are arbitrary strings (e.g., "AAA", "AAC").
Part 1: Single Forward Chain
Given a set of fragments that are guaranteed to form exactly one continuous chain following the rule prev.end_tag == next.start_tag, your task is to assemble and output the final concatenated string.
Example:
Input:
(XXX, ATG, "Hello")(ATG, GCA, "World")(GCA, TAG, "!")(TAG, YYY, "Done")
Output:
"HelloWorld!Done"
Part 2: Chain Traversal in Either Direction
Now, consider each fragment as a bidirectional connection between its start_tag and end_tag. You may traverse the final chain in either the forward or the reverse direction.
- Forward traversal: Outputs payloads in their original forward order.
- Reverse traversal: Outputs payloads in their reverse order (i.e., the last fragment's payload first, then the second to last, and so on).
Either the forward or reverse assembled string is considered an acceptable output.
For the example above, valid outputs include:
"HelloWorld!Done"(forward)"Done!WorldHello"(reverse)
Part 3: Multiple DNA Chains
In this final part, the input fragments may form multiple disjoint chains. It is still assumed that these can be arranged into simple chains without any branching within a single chain.
Your task is to output all assembled strings, one for each distinct chain. The order of these output strings does not matter.
Output Format
- For Part 1 and Part 2: A single string.
- For Part 3: A list or array of strings (one for each chain).