This question evaluates understanding of sequence reconstruction, graph modeling, and traversal/orientation constraints, focusing on ordering labeled fragments into a single non-repeating chain.
You are given a list of DNA fragments. Each fragment is represented by a Sequence object containing two endpoint labels and a DNA string payload.
Your task is to implement:
String shotgunSequence(List<Sequence> sequences)
The function must order the fragments into a single chain that uses every fragment exactly once, then return the reconstructed DNA string by concatenating the payload strings in that chain order.
Each fragment has:
startId
(string)
endId
(string)
payload
(string)
A fragment i can be followed by fragment j iff:
i.endId == j.startId
startId
/
endId
) are unique identifiers where applicable.
Fragments:
"AAA"
,
"AAC"
,
"AAAA"
)
"AGG"
,
"ACC"
,
"GGGG"
)
"AAC"
,
"ACT"
,
"TTTT"
)
"ACT"
,
"AGG"
,
"CCCC"
)
Valid label chain:
AAA → AAC → ACT → AGG → ACC
Output:
"AAAATTTTCCCCGGGG"
Now each fragment has:
tag1
(string)
tag2
(string)
payload
(string)
Fragment orientation is unknown: a fragment can be traversed as either tag1 → tag2 or tag2 → tag1.
Two consecutive fragments can be connected if they share a tag (i.e., the end tag of the current traversal equals a tag on the next fragment, choosing its traversal direction appropriately).
Fragments:
A
,
B
,
"AAAA"
)
B
,
C
,
"TTTT"
)
C
,
D
,
"CCCC"
)
D
,
B
,
"GGGG"
)
One valid tag walk:
A → B → C → D → B
Output:
"AAAATTTTCCCCGGGG"
Return the concatenation of payloads in the chosen fragment order. (No extra separators; do not merge/overlap payload strings.)