AO
Back

DNA Fragment Assembly: Chain by Tags, Then Unknown Direction, Then Several Chains

Also reported as Shotgun Sequence · Sort DNA Sequence

Phone ScreenPhone ScreenLast reported May 2026Medium Frequency

Problem Overview

The round: mostly a Microsoft AI (MAI) phone screen. Four candidates report it between November 2025 and May 2026: two on MAI teams and two on Copilot teams, where one got it in a senior onsite loop as its second coding round. It is one problem with follow-ups. One poster had 60 minutes, about 45 of them for coding, and had to run tests. Three reports give the same three steps, and this page grades all three: chain the fragments by their tags, then assemble them when a fragment's direction is unknown, then return every chain when there are several. The fourth report, from MAI, stops after the second step.

A fragment is a tuple (tag1, tag2, payload). Tags are short strings such as "AAA"; the payload is any string. The payload text is never reversed, only the order of the fragments.

Part 1 — chain by tags

def assemble(fragments: list[tuple[str, str, str]]) -> str: ...
  • Each fragment is (start_tag, end_tag, payload). One fragment's end tag equals the next one's start tag. Use every fragment. There is exactly one valid order, and every tag is unique.
  • Return the payloads joined in chain order. Example: ("AAA","AAC","AAAA"), ("AGG","ACC","GGGG"), ("AAC","ACT","TTTT"), ("ACT","AGG","CCCC") chain as AAA → AAC → ACT → AGG → ACC, so the answer is "AAAATTTTCCCCGGGG".

Part 2 — unknown direction

def assemble_undirected(fragments: list[tuple[str, str, str]]) -> str: ...
  • Now a fragment is (tag1, tag2, payload) with no start or end. Two fragments can join when they share a tag, in either direction. Use every fragment exactly once. A valid order always exists.
  • Tags can repeat. The reported example (A,B,AAAA), (B,C,TTTT), (C,D,CCCC), (D,B,GGGG) passes through B twice: A → B → C → D → B gives "AAAATTTTCCCCGGGG".
  • Either direction of the whole result is accepted ("HelloWorld!Done" or "Done!WorldHello"). When several orders are valid, the tests accept any one of them; that rule is ours, since the reports only say either direction is fine.

Part 3 — several chains

def assemble_all(fragments: list[tuple[str, str, str]]) -> list[str]: ...
  • As Part 2, but the fragments can form several chains that share no tag. Return one assembled string per chain, in any order. A single chain still comes back as a one-element list.

Notes: the function names, the tuple input and the list return in Part 3 are ours. One report uses a Sequence object with startId, endId and payload, and a single function shotgunSequence for both of the first two steps. The reports do not say whether Part 3 keeps the direction rule of Part 1 or of Part 2; two of them call it a follow-up on top of the unknown-direction step, so the tests use Part 2's rule. Whether a chain can close into a loop with no free end was asked in the threads and never answered, so no test has one.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion

Now each fragment just has two tags and you are not told which is the start and which is the end. Fragments can join in either direction when they share a tag. Implement the same thing.

Probes for: after Part 1, in all four reports

What if the input holds several chains that are not connected to each other? Detect and return all of them.

Probes for: after the unknown-direction step, in three reports

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Part 1 can also find the head by set difference of start and end tags and then follow the map—
it is the same On) idea. For Part 3, a BFS from each unvisited tag works as well as union-find.

What Reports Emphasize

Common mistakes: Running out of time on the unknown-direction step: one candidate nearly finished it and was rejected, another needed many hints to debug it and could only describe the last step. Assuming a tag appears at most twice: the reported example passes through B twice. Reversing payload text when a fragment is used backwards.

What candidates did: Commenters split on the second step. One reached for an Euler path with Hierholzer's algorithm; others said the guarantees (a valid order exists, every fragment is used) make it easy if you start from a tag that appears once. That shortcut only works on a plain chain; on the reported example, start from a tag that appears an odd number of times. For the last step a commenter said: build the graph, then search it.

Edge cases to test: The four-fragment example given out of order (answer AAAATTTTCCCCGGGG). The A-B, B-C, C-D, D-B example where a tag repeats. A chain presented backwards. A single fragment. Several chains that share no tag.

Practice

Write your own against 13 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Microsoft with friends?

Send them this page. It is free to read, no account needed.

More Microsoft Questions

Free preview

Every question in the Microsoft catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 39 Microsoft questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Microsoft · Phone Screen · Reported 4× across candidate reports
Is this helpful?