PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Reconstruct DNA from tagged fragments

Last updated: Apr 19, 2026

Quick Overview

This question evaluates understanding of sequence reconstruction, graph modeling, and traversal/orientation constraints, focusing on ordering labeled fragments into a single non-repeating chain.

  • nan
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Reconstruct DNA from tagged fragments

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: nan

Interview Round: Technical Screen

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: ```text 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. --- ## Part 1 (Directed chaining) Each fragment has: - `startId` (string) - `endId` (string) - `payload` (string) A fragment `i` can be followed by fragment `j` iff: - `i.endId == j.startId` ### Guarantees - All labels (`startId`/`endId`) are unique identifiers where applicable. - There exists **exactly one** valid ordering that uses **all** fragments. - The valid ordering forms one continuous chain. ### Example Fragments: - (`"AAA"`, `"AAC"`, `"AAAA"`) - (`"AGG"`, `"ACC"`, `"GGGG"`) - (`"AAC"`, `"ACT"`, `"TTTT"`) - (`"ACT"`, `"AGG"`, `"CCCC"`) Valid label chain: `AAA → AAC → ACT → AGG → ACC` Output: `"AAAATTTTCCCCGGGG"` --- ## Follow-up (Unknown direction / two tags) 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). ### Guarantees - At least one valid ordering exists that uses **all** fragments exactly once. - You must still use **all** fragments. ### Example Fragments: - (`A`, `B`, `"AAAA"`) - (`B`, `C`, `"TTTT"`) - (`C`, `D`, `"CCCC"`) - (`D`, `B`, `"GGGG"`) One valid tag walk: `A → B → C → D → B` Output: `"AAAATTTTCCCCGGGG"` --- ### What to return Return the concatenation of payloads in the chosen fragment order. (No extra separators; do not merge/overlap payload strings.)

Quick Answer: This question evaluates understanding of sequence reconstruction, graph modeling, and traversal/orientation constraints, focusing on ordering labeled fragments into a single non-repeating chain.

Related Interview Questions

  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Implement SFT Sample Packing - Microsoft (medium)
  • Implement SQL Table and DNA Ordering - Microsoft (medium)
  • Solve power jumps and graph tour - Microsoft (hard)
Microsoft logo
Microsoft
Mar 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

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.

Part 1 (Directed chaining)

Each fragment has:

  • startId (string)
  • endId (string)
  • payload (string)

A fragment i can be followed by fragment j iff:

  • i.endId == j.startId

Guarantees

  • All labels ( startId / endId ) are unique identifiers where applicable.
  • There exists exactly one valid ordering that uses all fragments.
  • The valid ordering forms one continuous chain.

Example

Fragments:

  • ( "AAA" , "AAC" , "AAAA" )
  • ( "AGG" , "ACC" , "GGGG" )
  • ( "AAC" , "ACT" , "TTTT" )
  • ( "ACT" , "AGG" , "CCCC" )

Valid label chain: AAA → AAC → ACT → AGG → ACC

Output: "AAAATTTTCCCCGGGG"

Follow-up (Unknown direction / two tags)

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).

Guarantees

  • At least one valid ordering exists that uses all fragments exactly once.
  • You must still use all fragments.

Example

Fragments:

  • ( A , B , "AAAA" )
  • ( B , C , "TTTT" )
  • ( C , D , "CCCC" )
  • ( D , B , "GGGG" )

One valid tag walk: A → B → C → D → B

Output: "AAAATTTTCCCCGGGG"

What to return

Return the concatenation of payloads in the chosen fragment order. (No extra separators; do not merge/overlap payload strings.)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.